Module: IIPolicy::Core
- Extended by:
- ActiveSupport::Concern
- Includes:
- Coactive::Initializer
- Included in:
- Base
- Defined in:
- lib/ii_policy/core.rb
Instance Method Summary collapse
- #allowed(action) ⇒ Object
- #call(action) ⇒ Object
- #call_all(action) ⇒ Object
- #initialize(args = {}) ⇒ Object
- #policy(item) ⇒ Object
Instance Method Details
#allowed(action) ⇒ Object
45 46 47 |
# File 'lib/ii_policy/core.rb', line 45 def allowed(action) call_all(action) end |
#call(action) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/ii_policy/core.rb', line 37 def call(action) if respond_to?(action) && !send(action) @_result = false else @_result = true end end |
#call_all(action) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ii_policy/core.rb', line 18 def call_all(action) planned = case IIPolicy.config.traversal when :preorder [self] + coactors when :postorder coactors + [self] when :inorder planned = coactors.in_groups(2, false) planned[0] + [self] + planned[1] end planned.each do |policy| result = policy == self ? call(action) : policy.new(@context).call_all(action) return false unless result end return true end |
#initialize(args = {}) ⇒ Object
14 15 16 |
# File 'lib/ii_policy/core.rb', line 14 def initialize(args = {}) super end |
#policy(item) ⇒ Object
49 50 51 52 |
# File 'lib/ii_policy/core.rb', line 49 def policy(item) context = self.class.context_class.new(@context.to_h.dup.merge(item: item)) self.class.lookup(item).new(context) end |