Module: Parentry::Strategy::Ltree::InstanceMethods

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

Instance Method Summary collapse

Instance Method Details

#ancestor_conditionsObject



29
30
31
# File 'lib/parentry/strategy/ltree/instance_methods.rb', line 29

def ancestor_conditions
  ["#{parentry_column} @> ?", parentry]
end

#cascade_parentryObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/parentry/strategy/ltree/instance_methods.rb', line 13

def cascade_parentry
  old_path, new_path = saved_changes[parentry_column]
  parentry_scope.where(
    ["#{parentry_column} <@ :tree AND id != :id", { tree: old_path, id: }]
  ).update_all(
    [
      "#{parentry_column} = :new_path || subpath(#{parentry_column}, nlevel(:old_path))",
      { new_path:, old_path: }
    ]
  )
end

#compute_parentryObject



9
10
11
# File 'lib/parentry/strategy/ltree/instance_methods.rb', line 9

def compute_parentry
  parent.present? ? "#{parent.parentry}.#{id}" : id.to_s
end

#parse_parentry(input = parentry) ⇒ Object



5
6
7
# File 'lib/parentry/strategy/ltree/instance_methods.rb', line 5

def parse_parentry(input = parentry)
  input.to_s.split('.').map(&:to_i)
end

#subtree_conditionsObject



25
26
27
# File 'lib/parentry/strategy/ltree/instance_methods.rb', line 25

def subtree_conditions
  ["#{parentry_column} <@ ?", parentry]
end