Class: Bunraku::RolesProxy

Inherits:
RoleProxyBase show all
Defined in:
lib/bunraku/proxies.rb

Instance Method Summary collapse

Methods inherited from RoleProxyBase

#==, #eql?, #hash

Constructor Details

#initialize(context, role_name, role_class, default = nil) ⇒ RolesProxy

Returns a new instance of RolesProxy.



93
94
95
96
# File 'lib/bunraku/proxies.rb', line 93

def initialize(context, role_name, role_class, default=nil)
  super(context, role_name, role_class)
  @default = default
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object (private)



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/bunraku/proxies.rb', line 109

def method_missing(name, *args)
  results = []
  @role_list.each do |role_holder|
    begin
      results << HolderProxy.new(role_holder).send(name, *args)
    rescue
      results << @default
    end
  end
  return results
end

Instance Method Details

#each(&block) ⇒ Object



98
99
100
101
102
103
104
105
106
107
# File 'lib/bunraku/proxies.rb', line 98

def each(&block)
  results = []
  @role_list.each do |role_holder|
    begin
      results << block.call(HolderProxy.new(role_holder))
    rescue
      results << @default
    end
  end      
end