Class: GroupDelegatorKlasses

Inherits:
Object
  • Object
show all
Includes:
SourceHelper
Defined in:
lib/group_delegator/group_delegator_klasses.rb

Direct Known Subclasses

GroupDelegator

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SourceHelper

#__set_sources_data, set_sources_data

Constructor Details

#initialize(*args) ⇒ GroupDelegatorKlasses

Returns a new instance of GroupDelegatorKlasses.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/group_delegator/group_delegator_klasses.rb', line 46

def initialize(*args)
  #changed self to self.class
  concurrency_model = self.class.__concurrency_model
  raise "No Source Classes set" unless self.class.__source_classes.size > 0
  @__objs_by_class = {}
  proxied_objs = []
  self.class.__source_classes.each do |klass|
    @__objs_by_class[klass] ||= []
    proxied_obj = klass.new(*args)
    @__objs_by_class[klass] << proxied_obj
  end
  proxied_objs = @__objs_by_class.values.flatten
   #p proxied_objs
   #proxied_objs = self.class.__source_classes.map {|klass| klass.new(*args) }
  sources_data = SourceHelper.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)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/group_delegator/group_delegator_klasses.rb', line 66

def method_missing(m, *args, &block)
  if @source_obj_methods.include? m
    resp = @instance_source_group.forward(m, *args, &block)
  else
    raise NoMethodError, "#{self.class} object can't find the method #{m} in any of its sources"
  end
end

Class Attribute Details

.__all_class_methodsObject

Returns the value of attribute __all_class_methods.



15
16
17
# File 'lib/group_delegator/group_delegator_klasses.rb', line 15

def __all_class_methods
  @__all_class_methods
end

.__class_source_groupObject

Returns the value of attribute __class_source_group.



15
16
17
# File 'lib/group_delegator/group_delegator_klasses.rb', line 15

def __class_source_group
  @__class_source_group
end

.__concurrency_modelObject

Returns the value of attribute __concurrency_model.



15
16
17
# File 'lib/group_delegator/group_delegator_klasses.rb', line 15

def __concurrency_model
  @__concurrency_model
end

Instance Attribute Details

#__objs_by_classObject (readonly)

Returns the value of attribute __objs_by_class.



44
45
46
# File 'lib/group_delegator/group_delegator_klasses.rb', line 44

def __objs_by_class
  @__objs_by_class
end

Class Method Details

.__set_source_classes(classes_to_proxy, concurrency_model = :iterative) ⇒ Object

sets the classes that will be proxied



18
19
20
21
22
23
24
25
# File 'lib/group_delegator/group_delegator_klasses.rb', line 18

def __set_source_classes(classes_to_proxy, concurrency_model = :iterative)
  @__concurrency_model = concurrency_model
  sources_data = SourceHelper.set_sources_data(classes_to_proxy)
  @source_obj_methods = sources_data[:source_methods]
  @sources = sources_data[:source_objs]
  @__all_class_methods = @source_obj_methods.keys
  @__class_source_group = SourceGroup.new(@sources, concurrency_model) if @sources.size > 0
end

.__source_classesObject



27
28
29
# File 'lib/group_delegator/group_delegator_klasses.rb', line 27

def __source_classes
  @sources
end

.method_missing(m, *args, &block) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/group_delegator/group_delegator_klasses.rb', line 36

def self.method_missing(m, *args, &block)
  if self.__all_class_methods.include? m
    resp = self.__class_source_group.forward(m, *args, &block)
    else
    raise NoMethodError, "#{self.class} can't find the class method #{m} in any of its sources"
  end
end