| Index: third_party/grpc/src/ruby/lib/grpc/core/time_consts.rb
|
| diff --git a/third_party/protobuf/ruby/lib/google/protobuf/message_exts.rb b/third_party/grpc/src/ruby/lib/grpc/core/time_consts.rb
|
| similarity index 55%
|
| copy from third_party/protobuf/ruby/lib/google/protobuf/message_exts.rb
|
| copy to third_party/grpc/src/ruby/lib/grpc/core/time_consts.rb
|
| index e10266ba2f3637d655c2de89c285558c987c613b..c8eae7806b349b78affbcb279cc46210740d4c44 100644
|
| --- a/third_party/protobuf/ruby/lib/google/protobuf/message_exts.rb
|
| +++ b/third_party/grpc/src/ruby/lib/grpc/core/time_consts.rb
|
| @@ -1,6 +1,5 @@
|
| -# Protocol Buffers - Google's data interchange format
|
| -# Copyright 2008 Google Inc. All rights reserved.
|
| -# https://developers.google.com/protocol-buffers/
|
| +# Copyright 2015-2016, Google Inc.
|
| +# All rights reserved.
|
| #
|
| # Redistribution and use in source and binary forms, with or without
|
| # modification, are permitted provided that the following conditions are
|
| @@ -28,26 +27,45 @@
|
| # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
| -module Google
|
| - module Protobuf
|
| - module MessageExts
|
| +require 'grpc/grpc'
|
|
|
| - #this is only called in jruby; mri loades the ClassMethods differently
|
| - def self.included(klass)
|
| - klass.extend(ClassMethods)
|
| - end
|
| -
|
| - module ClassMethods
|
| - end
|
| -
|
| - def to_json
|
| - self.class.encode_json(self)
|
| - end
|
| -
|
| - def to_proto
|
| - self.class.encode(self)
|
| +# GRPC contains the General RPC module.
|
| +module GRPC
|
| + module Core
|
| + # TimeConsts is a module from the C extension.
|
| + #
|
| + # Here it's re-opened to add a utility func.
|
| + module TimeConsts
|
| + # Converts a time delta to an absolute deadline.
|
| + #
|
| + # Assumes timeish is a relative time, and converts its to an absolute,
|
| + # with following exceptions:
|
| + #
|
| + # * if timish is one of the TimeConsts.TimeSpec constants the value is
|
| + # preserved.
|
| + # * timish < 0 => TimeConsts.INFINITE_FUTURE
|
| + # * timish == 0 => TimeConsts.ZERO
|
| + #
|
| + # @param timeish [Number|TimeSpec]
|
| + # @return timeish [Number|TimeSpec]
|
| + def from_relative_time(timeish)
|
| + if timeish.is_a? TimeSpec
|
| + timeish
|
| + elsif timeish.nil?
|
| + TimeConsts::ZERO
|
| + elsif !timeish.is_a? Numeric
|
| + fail(TypeError,
|
| + "Cannot make an absolute deadline from #{timeish.inspect}")
|
| + elsif timeish < 0
|
| + TimeConsts::INFINITE_FUTURE
|
| + elsif timeish.zero?
|
| + TimeConsts::ZERO
|
| + else
|
| + Time.now + timeish
|
| + end
|
| end
|
|
|
| + module_function :from_relative_time
|
| end
|
| end
|
| end
|
|
|