Sha256: 45d6f7d79edd0a7f31e76df59a4de557547db45a4e73c48d0843e51d86c3e9c4
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
require 'ransack/visitor' module Ransack class Context attr_reader :arel_visitor class << self def for_class(klass, options = {}) if klass < ActiveRecord::Base Adapters::ActiveRecord::Context.new(klass, options) end end def for_object(object, options = {}) case object when ActiveRecord::Relation Adapters::ActiveRecord::Context.new(object.klass, options) end end end # << self def initialize(object, options = {}) @object = relation_for(object) @klass = @object.klass @join_dependency = join_dependency(@object) @join_type = options[:join_type] || Polyamorous::OuterJoin @search_key = options[:search_key] || Ransack.options[:search_key] @associations_pot = {} @lock_associations = [] @base = @join_dependency.instance_variable_get(:@join_root) end def bind_pair_for(key) @bind_pairs ||= {} @bind_pairs[key] ||= begin parent, attr_name = get_parent_and_attribute_name(key.to_s) [parent, attr_name] if parent && attr_name end end def klassify(obj) if Class === obj && ::ActiveRecord::Base > obj obj elsif obj.respond_to? :klass obj.klass else raise ArgumentError, "Don't know how to klassify #{obj.inspect}" end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ransack-2.3.2 | lib/ransack/adapters/active_record/ransack/context.rb |
ransack-2.3.1 | lib/ransack/adapters/active_record/ransack/context.rb |