Sha256: 282e1132f8ce0b2015d6f9577784152e557f6ae62cff05d16111ce627fe8bf83

Contents?: true

Size: 1001 Bytes

Versions: 1

Compression:

Stored size: 1001 Bytes

Contents

module Parentry
  module Strategy
    module Array
      module InstanceMethods
        def parse_parentry(input = parentry)
          input
        end

        def compute_parentry
          return [] unless persisted?

          parent.present? ? parent.parentry + [id] : [id]
        end

        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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
parentry-1.8.0 lib/parentry/strategy/array/instance_methods.rb