Module: Granite::Action::Policies::ClassMethods
- Defined in:
- lib/granite/action/policies.rb
Instance Method Summary collapse
-
#allow_if(&block) ⇒ Object
The simplies policy.
- #allow_self ⇒ Object
Instance Method Details
#allow_if(&block) ⇒ Object
The simplies policy. Takes block and executes it returning boolean result. Multiple policies are reduced with ||
class Action < Granite::Action
allow_if { performer.is_a?(Recruiter) }
allow_if { performer.is_a?(AdvancedRecruiter) }
end
The first argument in block is a current action performer, so it is possible to use a short-cut performer methods:
class Action < Granite::Action
allow_if(&:staff?)
end
49 50 51 |
# File 'lib/granite/action/policies.rb', line 49 def allow_if(&block) self._policies += [block] end |
#allow_self ⇒ Object
53 54 55 |
# File 'lib/granite/action/policies.rb', line 53 def allow_self allow_if { performer == subject } end |