Class: Ribbon::Intercom::Package
- Inherits:
-
Object
- Object
- Ribbon::Intercom::Package
- Includes:
- Utils::Mixins::MockSafe
- Defined in:
- lib/ribbon/intercom/package.rb
Instance Attribute Summary collapse
-
#sdk ⇒ Object
readonly
Class Methods.
Class Method Summary collapse
- ._package_obj(subject, data = nil) ⇒ Object
- .decode_subject(encoded_subject) ⇒ Object
- .encode_subject(subject) ⇒ Object
-
.init_packages(object, sdk) ⇒ Object
Walks the object and initializes all packages (i.e., sets them up to be accessed by the end-user on the client).
-
.package(subject) ⇒ Object
Package up any non-basic objects that include Packageable::Mixin.
Instance Method Summary collapse
-
#begin ⇒ Object
Begin a method chain (must be completed with ‘#end`).
-
#initialize(subject_data = nil, data = nil) ⇒ Package
constructor
A new instance of Package.
Methods included from Utils::Mixins::MockSafe
#mock_safe, #mock_safe!, #mock_safe?
Constructor Details
#initialize(subject_data = nil, data = nil) ⇒ Package
Returns a new instance of Package.
52 53 54 55 |
# File 'lib/ribbon/intercom/package.rb', line 52 def initialize(subject_data=nil, data=nil) @_subject_data = subject_data @_data = data end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object (private)
72 73 74 75 76 77 78 79 80 |
# File 'lib/ribbon/intercom/package.rb', line 72 def method_missing(meth, *args, &block) if @_data && @_data.key?(meth) @_data[meth] elsif sdk _call(meth, *args) else super end end |
Instance Attribute Details
#sdk ⇒ Object (readonly)
Class Methods
50 51 52 |
# File 'lib/ribbon/intercom/package.rb', line 50 def sdk @sdk end |
Class Method Details
._package_obj(subject, data = nil) ⇒ Object
27 28 29 |
# File 'lib/ribbon/intercom/package.rb', line 27 def _package_obj(subject, data=nil) new(encode_subject(subject), data) end |
.decode_subject(encoded_subject) ⇒ Object
35 36 37 |
# File 'lib/ribbon/intercom/package.rb', line 35 def decode_subject(encoded_subject) Marshal.load(encoded_subject) end |
.encode_subject(subject) ⇒ Object
31 32 33 |
# File 'lib/ribbon/intercom/package.rb', line 31 def encode_subject(subject) Marshal.dump(subject) end |
.init_packages(object, sdk) ⇒ Object
Walks the object and initializes all packages (i.e., sets them up to be accessed by the end-user on the client).
42 43 44 45 46 47 |
# File 'lib/ribbon/intercom/package.rb', line 42 def init_packages(object, sdk) Utils.walk(object) { |object| object.send(:_init, sdk) if object.is_a?(Package) object } end |
.package(subject) ⇒ Object
Package up any non-basic objects that include Packageable::Mixin.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ribbon/intercom/package.rb', line 10 def package(subject) Utils.walk(subject) { |subject, context| if Utils.basic_type?(subject) subject elsif context == :hash_key # Hash keys must be basic types. raise Errors::UnsafeResponseError, subject.inspect elsif subject.is_a?(Packageable::Mixin) _package_obj(subject, package(subject.package_data)) elsif subject.is_a?(Class) && subject < Packageable::Mixin _package_obj(subject) else raise Errors::UnsafeResponseError, subject.inspect end } end |
Instance Method Details
#begin ⇒ Object
Begin a method chain (must be completed with ‘#end`).
When ‘#end` is called on the method chain, the chain will be resolved remotely. This allows the chain of methods to be executed in one round-trip.
62 63 64 65 66 67 68 |
# File 'lib/ribbon/intercom/package.rb', line 62 def begin Utils::MethodChain.begin { |methods| queue = Packet::MethodQueue.new methods.each { |meth, *args| queue.enqueue(meth, *args) } _send_method_queue(queue) } end |