Module: Parentry::Strategy::Array::InstanceMethods
- Defined in:
- lib/parentry/strategy/array/instance_methods.rb
Instance Method Summary collapse
- #ancestor_conditions ⇒ Object
- #cascade_parentry ⇒ Object
- #compute_parentry ⇒ Object
- #parse_parentry(input = parentry) ⇒ Object
- #subtree_conditions ⇒ Object
Instance Method Details
#ancestor_conditions ⇒ Object
31 32 33 |
# File 'lib/parentry/strategy/array/instance_methods.rb', line 31 def ancestor_conditions ["#{parentry_column} <@ ARRAY[?]::integer[]", parentry] end |
#cascade_parentry ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/parentry/strategy/array/instance_methods.rb', line 15 def cascade_parentry old_path, new_path = saved_changes[parentry_column] parentry_scope.where( ["#{parentry_column} @> ARRAY[:tree]::integer[] AND id != :id", { tree: old_path, id: }] ).update_all( [ "#{parentry_column} = array_cat(ARRAY[?], #{parentry_column}[?:array_length(#{parentry_column}, 1)])", new_path, old_path.size + 1 ] ) end |
#compute_parentry ⇒ Object
9 10 11 12 13 |
# File 'lib/parentry/strategy/array/instance_methods.rb', line 9 def compute_parentry return [] unless persisted? parent.present? ? parent.parentry + [id] : [id] end |
#parse_parentry(input = parentry) ⇒ Object
5 6 7 |
# File 'lib/parentry/strategy/array/instance_methods.rb', line 5 def parse_parentry(input = parentry) input end |
#subtree_conditions ⇒ Object
27 28 29 |
# File 'lib/parentry/strategy/array/instance_methods.rb', line 27 def subtree_conditions ["#{parentry_column} @> ARRAY[?]::integer[]", parentry] end |