Sha256: 0ff6e4dad143fa5bb05963d885f0ac000ef1d3afbcf2ac926061a2aa2c9df6f6

Contents?: true

Size: 966 Bytes

Versions: 5

Compression:

Stored size: 966 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] AND id != :id", tree: old_path, id: 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[?]", parentry]
        end

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
parentry-1.3.0 lib/parentry/strategy/array/instance_methods.rb
parentry-1.2.0 lib/parentry/strategy/array/instance_methods.rb
parentry-1.1.0 lib/parentry/strategy/array/instance_methods.rb
parentry-1.0.1 lib/parentry/strategy/array/instance_methods.rb
parentry-1.0.0 lib/parentry/strategy/array/instance_methods.rb