Class: Policy::Proxy
- Inherits:
-
Object
- Object
- Policy::Proxy
- Defined in:
- lib/egoist/proxy.rb
Instance Method Summary collapse
-
#initialize(policy) ⇒ Proxy
constructor
A new instance of Proxy.
- #method_missing(name, *args, &block) ⇒ Object
Constructor Details
#initialize(policy) ⇒ Proxy
36 37 38 |
# File 'lib/egoist/proxy.rb', line 36 def initialize policy @policy = policy end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/egoist/proxy.rb', line 40 def method_missing name, *args, &block name = name.to_s.sub(/(.)$/, '') action = $1 @policy.can?(name, *args) if action == '!' @policy.model || true else true end rescue Policy::Error => error msg = yield error if block_given? if action == '!' raise msg ? Policy::Error.new(msg) : error elsif action == '?' false else raise ArgumentError.new('Bad policy method %s' % name) end end |