Module: Monarchy::ActsAsResource::InstanceMethods
- Defined in:
- lib/monarchy/acts_as_resource.rb
Instance Method Summary collapse
- #accessible_for(user) ⇒ Object
- #children ⇒ Object
- #children=(array) ⇒ Object
- #ensure_hierarchy(force = false) ⇒ Object
- #parent ⇒ Object
- #parent=(resource) ⇒ Object
Instance Method Details
#accessible_for(user) ⇒ Object
98 99 100 |
# File 'lib/monarchy/acts_as_resource.rb', line 98 def accessible_for(user) hierarchy.accessible_for(user) end |
#children ⇒ Object
79 80 81 |
# File 'lib/monarchy/acts_as_resource.rb', line 79 def children @children ||= children_resources end |
#children=(array) ⇒ Object
83 84 85 86 |
# File 'lib/monarchy/acts_as_resource.rb', line 83 def children=(array) hierarchy&.update(children: hierarchies_for(array)) @children = array end |
#ensure_hierarchy(force = false) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/monarchy/acts_as_resource.rb', line 88 def ensure_hierarchy(force = false) return nil unless self.class.automatic_hierarchy || force self.hierarchy ||= Monarchy.hierarchy_class.create( resource: self, parent: parent.try(:hierarchy), children: hierarchies_for(children) ) end |
#parent ⇒ Object
69 70 71 |
# File 'lib/monarchy/acts_as_resource.rb', line 69 def parent @parent = hierarchy.try(:parent).try(:resource) || @parent end |
#parent=(resource) ⇒ Object
73 74 75 76 77 |
# File 'lib/monarchy/acts_as_resource.rb', line 73 def parent=(resource) Monarchy::Validators.resource(resource, true) hierarchy&.update(parent: resource.try(:ensure_hierarchy)) @parent = resource end |