Sha256: ac00a0335c675c02f41ac29c57a0e875670c476b6112db816a6d0ede5bab782e

Contents?: true

Size: 1.13 KB

Versions: 47

Compression:

Stored size: 1.13 KB

Contents

module ClosureTree
  module DeterministicOrdering
    extend ActiveSupport::Concern

    module ClassAndInstanceMethods
      def order_column
        o = order_option
        o.split(' ', 2).first if o
      end

      def require_order_column
        raise ":order value, '#{order_option}', isn't a column" if order_column.nil?
      end

      def order_column_sym
        require_order_column
        order_column.to_sym
      end

      def quoted_order_column(include_table_name = true)
        require_order_column
        prefix = include_table_name ? "#{quoted_table_name}." : ""
        "#{prefix}#{connection.quote_column_name(order_column)}"
      end
    end

    include ClassAndInstanceMethods

    module ClassMethods
      include ClassAndInstanceMethods
    end

    def order_value
      read_attribute(order_column_sym)
    end

    def order_value=(new_order_value)
      write_attribute(order_column_sym, new_order_value)
    end

    def siblings_before
      siblings.where(["#{quoted_order_column} < ?", order_value])
    end

    def siblings_after
      siblings.where(["#{quoted_order_column} > ?", order_value])
    end
  end
end

Version data entries

47 entries across 47 versions & 2 rubygems

Version Path
lalala-4.0.0.dev.136 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.135 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.134 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.133 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.132 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.131 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.129 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.128 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.126 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.125 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.124 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.123 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.118 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.116 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.114 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.113 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.111 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.109 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.107 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb
lalala-4.0.0.dev.94 vendor/deps/closure_tree/lib/closure_tree/deterministic_ordering.rb