Class: HasDynamicColumns::ActiveRecord::QueryMethods::WhereChain

Inherits:
Object
  • Object
show all
Defined in:
lib/has_dynamic_columns/active_record/v3/query_methods.rb

Overview

Instance Method Summary collapse

Constructor Details

#initialize(scope) ⇒ WhereChain

Returns a new instance of WhereChain.



40
41
42
# File 'lib/has_dynamic_columns/active_record/v3/query_methods.rb', line 40

def initialize(scope)
	@scope = scope
end

Instance Method Details

#has_dynamic_columns(opts = :chain, *rest) ⇒ Object

Extends where to chain a has_dynamic_columns method This builds all the joins needed to search the has_dynamic_columns_data tables



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/has_dynamic_columns/active_record/v3/query_methods.rb', line 46

def has_dynamic_columns(opts = :chain, *rest)
	# Map
	dynamic_columns_value = {
		:scope => nil,
		:where => @scope.send(:build_where, opts, rest)
	}
	@scope.where_dynamic_columns_values = dynamic_columns_value

	chain = ::ActiveRecord::QueryMethods::WhereChain.new(@scope)
	chain.instance_eval do
		# Make outer scope variable accessible
		@dynamic_columns_value = dynamic_columns_value

		# Extends where to chain with a has_scope method
		# This scopes the where from above
		def with_scope(opt)
			@dynamic_columns_value[:scope] = opt

			@scope
		end
		def without_scope
			@scope
		end
	end

	chain
end