Sha256: b0fb18256dfdb1ea6d29f9832c8a7d9520f45c43b66f8dabfdabb6fdf3c29805

Contents?: true

Size: 747 Bytes

Versions: 3

Compression:

Stored size: 747 Bytes

Contents

module OrderedTree
  module InstanceMethods
    module Misc
      protected

      def foreign_key_column
        :"#{ordered_tree_config[:foreign_key]}"
      end

      def order_column
        :"#{ordered_tree_config[:order]}"
      end

      private

      def scope_condition
        return @scope_condition if defined?(@scope_condition)
        scope = self.class.ordered_tree_config[:scope]
        # If the scope is something like :person, then turn it into :person_id
        scope = :"#{scope}_id" if scope.is_a?(Symbol) && scope.to_s !~ /_id$/

        @scope_condition = if scope
          self.class.send(:sanitize_sql_hash_for_conditions, {scope => send(scope)})
        else
          "1=1"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ordered_tree-1.0.0 lib/ordered_tree/instance_methods/misc.rb
ordered_tree-0.2.1 lib/ordered_tree/instance_methods/misc.rb
ordered_tree-0.1.9 lib/ordered_tree/instance_methods/misc.rb