Module: Parentry::InstanceMethods
- Defined in:
- lib/parentry/instance_methods.rb
Instance Method Summary collapse
- #ancestor_ids_was ⇒ Object
- #assign_parentry ⇒ Object
- #cache_parentry_depth ⇒ Object
- #commit_parentry ⇒ Object
- #parentry ⇒ Object
- #parentry_scope ⇒ Object
- #prevent_circular_parentry ⇒ Object
- #touch_ancestors_callback ⇒ Object
- #touch_callbacks_disabled? ⇒ Boolean
- #without_touch_callbacks ⇒ Object
Instance Method Details
#ancestor_ids_was ⇒ Object
47 48 49 50 51 |
# File 'lib/parentry/instance_methods.rb', line 47 def ancestor_ids_was return [] unless saved_changes[parentry_column] parse_parentry(saved_changes[parentry_column][0]).tap(&:pop) end |
#assign_parentry ⇒ Object
16 17 18 |
# File 'lib/parentry/instance_methods.rb', line 16 def assign_parentry write_attribute(parentry_column, compute_parentry) end |
#cache_parentry_depth ⇒ Object
20 21 22 |
# File 'lib/parentry/instance_methods.rb', line 20 def cache_parentry_depth write_attribute(:parentry_depth, depth) end |
#commit_parentry ⇒ Object
12 13 14 |
# File 'lib/parentry/instance_methods.rb', line 12 def commit_parentry update_column(parentry_column, compute_parentry) end |
#parentry ⇒ Object
24 25 26 |
# File 'lib/parentry/instance_methods.rb', line 24 def parentry read_attribute(parentry_column) end |
#parentry_scope ⇒ Object
3 4 5 |
# File 'lib/parentry/instance_methods.rb', line 3 def parentry_scope self.class.base_class end |
#prevent_circular_parentry ⇒ Object
7 8 9 10 |
# File 'lib/parentry/instance_methods.rb', line 7 def prevent_circular_parentry computed = parse_parentry(compute_parentry) errors.add(:parentry, 'contains a circular reference') unless computed.uniq == computed end |
#touch_ancestors_callback ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/parentry/instance_methods.rb', line 28 def touch_ancestors_callback return unless touch_ancestors return if touch_callbacks_disabled? parentry_scope.where(id: ancestor_ids_was + ancestor_ids).each do |ancestor| ancestor.without_touch_callbacks { ancestor.touch } end end |
#touch_callbacks_disabled? ⇒ Boolean
43 44 45 |
# File 'lib/parentry/instance_methods.rb', line 43 def touch_callbacks_disabled? @disable_touch_callbacks end |
#without_touch_callbacks ⇒ Object
37 38 39 40 41 |
# File 'lib/parentry/instance_methods.rb', line 37 def without_touch_callbacks @disable_touch_callbacks = true yield @disable_touch_callbacks = false end |