Module: Monarchy::ActsAsResource::InstanceMethods
- Defined in:
- lib/monarchy/acts_as_resource.rb
Instance Method Summary collapse
- #children ⇒ Object
- #children=(array) ⇒ Object
- #ensure_hierarchy(force = false) ⇒ Object
- #parent ⇒ Object
- #parent=(resource) ⇒ Object
Instance Method Details
#children ⇒ Object
78 79 80 |
# File 'lib/monarchy/acts_as_resource.rb', line 78 def children @children ||= children_resources end |
#children=(array) ⇒ Object
82 83 84 85 |
# File 'lib/monarchy/acts_as_resource.rb', line 82 def children=(array) hierarchy&.update(children: hierarchies_for(array)) @children = array end |
#ensure_hierarchy(force = false) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/monarchy/acts_as_resource.rb', line 87 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
68 69 70 |
# File 'lib/monarchy/acts_as_resource.rb', line 68 def parent @parent = hierarchy.try(:parent).try(:resource) || @parent end |
#parent=(resource) ⇒ Object
72 73 74 75 76 |
# File 'lib/monarchy/acts_as_resource.rb', line 72 def parent=(resource) Monarchy::Validators.resource(resource, true) hierarchy&.update(parent: resource.try(:ensure_hierarchy)) @parent = resource end |