Module: Parentry::Strategy::Array::InstanceMethods

Defined in:
lib/parentry/strategy/array/instance_methods.rb

Instance Method Summary collapse

Instance Method Details

#ancestor_conditionsObject



31
32
33
# File 'lib/parentry/strategy/array/instance_methods.rb', line 31

def ancestor_conditions
  ["#{parentry_column} <@ ARRAY[?]::integer[]", parentry]
end

#cascade_parentryObject



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_parentryObject



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_conditionsObject



27
28
29
# File 'lib/parentry/strategy/array/instance_methods.rb', line 27

def subtree_conditions
  ["#{parentry_column} @> ARRAY[?]::integer[]", parentry]
end