Class: Dry::Ability::Rule::Or
- Inherits:
-
Object
- Object
- Dry::Ability::Rule::Or
- Includes:
- Dry::Ability::RuleInterface
- Defined in:
- lib/dry/ability/rule.rb
Instance Method Summary collapse
- #accessible? ⇒ Boolean
- #attributes_for(account, object) ⇒ Object
- #call(account, object) ⇒ Object
- #scope_for(account, subject) ⇒ Object
- #|(other) ⇒ Object
Methods included from Dry::Ability::RuleInterface
Instance Method Details
#accessible? ⇒ Boolean
105 106 107 |
# File 'lib/dry/ability/rule.rb', line 105 def accessible? true end |
#attributes_for(account, object) ⇒ Object
92 93 94 95 96 |
# File 'lib/dry/ability/rule.rb', line 92 def attributes_for(account, object) items.reduce({}) do |result, rule| result.deep_merge!(rule.attributes_for(rule, object)); result end end |
#call(account, object) ⇒ Object
86 87 88 89 90 |
# File 'lib/dry/ability/rule.rb', line 86 def call(account, object) items.reduce(false) do |result, rule| result || rule[account, object] end end |
#scope_for(account, subject) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/dry/ability/rule.rb', line 98 def scope_for(account, subject) base_relations = items.map { |rule| rule.scope_for(account, subject) } condit = base_relations.map { |r| r.except(:joins) }.reduce(:or) merged = base_relations.map { |r| r.except(:where) }.reduce(:merge) merged.merge(condit) end |
#|(other) ⇒ Object
109 110 111 |
# File 'lib/dry/ability/rule.rb', line 109 def |(other) self.class.new([*items, other]) end |