Class: Dry::Ability::Rule::Or

Inherits:
Object
  • Object
show all
Includes:
Dry::Ability::RuleInterface
Defined in:
lib/dry/ability/rule.rb

Instance Method Summary collapse

Methods included from Dry::Ability::RuleInterface

#[]

Instance Method Details

#accessible?Boolean

Returns:

  • (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(, 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(, object)
  items.reduce(false) do |result, rule|
    result || rule[, 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(, subject)
  base_relations = items.map { |rule| rule.scope_for(, 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