inspect on Ransack::Search objects now will not load entire object graph
This means that: 1) inspect calls will be faster 2) inspect calls will be easier to understand 3) queries won't be executed until #result is called on the Search object Fixes #115 with #121
This commit is contained in:
parent
2a6f9cc50b
commit
953ec1b502
|
@ -44,6 +44,10 @@ module Ransack
|
|||
false
|
||||
end
|
||||
|
||||
def inspect
|
||||
"Attribute <#{name}>"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -200,6 +200,13 @@ module Ransack
|
|||
predicate.type || (attributes.first && attributes.first.type)
|
||||
end
|
||||
|
||||
def inspect
|
||||
data =[['attributes', a.try(:map, &:name)], ['predicate', p], ['combinator', m], ['values', v.try(:map, &:value)]].reject { |e|
|
||||
e[1].blank?
|
||||
}.map { |v| "#{v[0]}: #{v[1]}" }.join(', ')
|
||||
"Condition <#{data}>"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def valid_combinator?
|
||||
|
|
|
@ -154,6 +154,13 @@ module Ransack
|
|||
self
|
||||
end
|
||||
|
||||
def inspect
|
||||
data =[['conditions', conditions], ['combinator', combinator]].reject { |e|
|
||||
e[1].blank?
|
||||
}.map { |v| "#{v[0]}: #{v[1]}" }.join(', ')
|
||||
"Grouping <#{data}>"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def write_attribute(name, val)
|
||||
|
|
|
@ -98,6 +98,10 @@ module Ransack
|
|||
end
|
||||
end
|
||||
|
||||
def inspect
|
||||
"Value <#{value}>"
|
||||
end
|
||||
|
||||
def array_of_arrays?(val)
|
||||
Array === val && Array === val.first
|
||||
end
|
||||
|
|
|
@ -90,6 +90,10 @@ module Ransack
|
|||
end
|
||||
end
|
||||
|
||||
def inspect
|
||||
"Ransack::Search<class: #{klass.name}, base: #{base.inspect}>"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def collapse_multiparameter_attributes!(attrs)
|
||||
|
|
|
@ -104,6 +104,11 @@ module Ransack
|
|||
condition.attributes.first.name.should eq 'name'
|
||||
condition.value.should eq ['Ernie', 'Bert']
|
||||
end
|
||||
|
||||
it 'does not evaluate the query on #inspect' do
|
||||
search = Search.new(Person, :children_id_in => [1, 2, 3])
|
||||
search.inspect.should_not match /ActiveRecord/
|
||||
end
|
||||
end
|
||||
|
||||
describe '#result' do
|
||||
|
|
Loading…
Reference in New Issue