Class: GroupDelegatorInstances
- Inherits:
-
Object
- Object
- GroupDelegatorInstances
- Includes:
- SourceHelper
- Defined in:
- lib/group_delegator/group_delegator_instances.rb
Overview
Takes a set of instantiated objects as arguments and will concurently delegate method calls to each instance in the set. Built in concurrency models include:
-
iterative (iterates the method calls on each object in the set)
-
threaded (all method calls are done in parallel until all conclude
-
first response (continues once any in the set complete the method)
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(proxied_objs, concurrency_model = :iterative) ⇒ GroupDelegatorInstances
constructor
object methods, only.
- #method_missing(m, *args, &block) ⇒ Object
Methods included from SourceHelper
#__set_sources_data, set_sources_data
Constructor Details
#initialize(proxied_objs, concurrency_model = :iterative) ⇒ GroupDelegatorInstances
object methods, only
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/group_delegator/group_delegator_instances.rb', line 14 def initialize(proxied_objs, concurrency_model = :iterative) @source_objects = [] #contains the delegated objects @source_obj_methods = {} #map of all methods to the objects that use them raise "No source instances set" unless proxied_objs.size > 0 sources_data = __set_sources_data(proxied_objs) @source_obj_methods = sources_data[:source_methods] @source_objects = sources_data[:source_objs] @instance_source_group = SourceGroup.new(@source_objects, concurrency_model) self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/group_delegator/group_delegator_instances.rb', line 25 def method_missing(m, *args, &block) if @source_obj_methods.include? m resp = @instance_source_group.forward(m, *args, &block) else raise NoMethodError, "GroupDelegatorKlasses object can't find the method #{m} in any of its sources" end end |