Module: Roleful::ClassMethods
- Defined in:
- lib/roleful/inclusion.rb
Instance Method Summary collapse
-
#delegate_permission(*methods) ⇒ Object
Delegates method calls to the object’s #role_proxy, accounting for cases when there are multiple roles for the given object.
- #role(*args, &block) ⇒ Object
Instance Method Details
#delegate_permission(*methods) ⇒ Object
Delegates method calls to the object’s #role_proxy, accounting for cases when there are multiple roles for the given object.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/roleful/inclusion.rb', line 51 def (*methods) = methods.pop raise ArgumentError, "Delegation needs a target." unless .is_a?(Hash) && to = [:to] methods.each do |method| module_eval(<<-EOS, "(__DELEGATION__)", 1) def #{method}(*args, &block) target = Array(send(#{to.inspect})) target.any? do |to| to.__send__(#{method.inspect}, self, *args, &block) end end EOS end end |
#role(*args, &block) ⇒ Object
43 44 45 46 47 |
# File 'lib/roleful/inclusion.rb', line 43 def role(*args, &block) = args.last.is_a?(Hash) ? args.pop : {} roles = [:all].eql?(args) ? all_roles : args roles.each { |name| define_role(name.to_sym, , &block) } end |