Class: MongoidAbility::ValuesForAccessibleQuery
- Inherits:
-
Struct
- Object
- Struct
- MongoidAbility::ValuesForAccessibleQuery
- Defined in:
- lib/mongoid_ability/values_for_accessible_query.rb
Instance Attribute Summary collapse
-
#ability ⇒ Object
Returns the value of attribute ability.
-
#action ⇒ Object
Returns the value of attribute action.
-
#base_class ⇒ Object
Returns the value of attribute base_class.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#ability ⇒ Object
Returns the value of attribute ability
2 3 4 |
# File 'lib/mongoid_ability/values_for_accessible_query.rb', line 2 def ability @ability end |
#action ⇒ Object
Returns the value of attribute action
2 3 4 |
# File 'lib/mongoid_ability/values_for_accessible_query.rb', line 2 def action @action end |
#base_class ⇒ Object
Returns the value of attribute base_class
2 3 4 |
# File 'lib/mongoid_ability/values_for_accessible_query.rb', line 2 def base_class @base_class end |
#options ⇒ Object
Returns the value of attribute options
2 3 4 |
# File 'lib/mongoid_ability/values_for_accessible_query.rb', line 2 def @options end |
Class Method Details
.call(*args) ⇒ Object
3 4 5 |
# File 'lib/mongoid_ability/values_for_accessible_query.rb', line 3 def self.call(*args) new(*args).call end |
Instance Method Details
#call ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mongoid_ability/values_for_accessible_query.rb', line 9 def call closed_types = [] # [cls] open_types_and_ids = [] # OpenStruct.new(type: …, id: …) closed_ids = [] # [id] base_class_and_descendants.each do |cls| closed_types << cls.to_s if ability.cannot?(action, cls, ) id_locks(cls).each do |lock| if ability.can?(action, cls.new(_id: lock.subject_id), ) open_types_and_ids << OpenStruct.new(type: cls.to_s, id: lock.subject_id) else closed_ids << lock.subject_id end end end OpenStruct.new( closed_types: closed_types, open_types_and_ids: open_types_and_ids, closed_ids: closed_ids ) end |