ransack 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -4
- data/lib/ransack/adapters/active_record/3.0/context.rb +1 -2
- data/lib/ransack/adapters/active_record/base.rb +2 -2
- data/lib/ransack/adapters/active_record/context.rb +1 -2
- data/lib/ransack/ransacker.rb +0 -2
- data/lib/ransack/version.rb +1 -1
- data/spec/ransack/search_spec.rb +0 -6
- metadata +16 -16
data/README.md
CHANGED
@@ -55,15 +55,13 @@ If you're coming from MetaSearch, things to note:
|
|
55
55
|
is passed to it.
|
56
56
|
3. Common ActiveRecord::Relation methods are no longer delegated by the search object.
|
57
57
|
Instead, you will get your search results (an ActiveRecord::Relation in the case of
|
58
|
-
the ActiveRecord adapter) via a call to `Search#result`.
|
59
|
-
`result` will generate a `SELECT DISTINCT` to avoid returning duplicate rows, even if
|
60
|
-
conditions on a join would otherwise result in some.
|
58
|
+
the ActiveRecord adapter) via a call to `Search#result`.
|
61
59
|
|
62
60
|
In your controller:
|
63
61
|
|
64
62
|
def index
|
65
63
|
@q = Person.search(params[:q])
|
66
|
-
@people = @q.result
|
64
|
+
@people = @q.result
|
67
65
|
end
|
68
66
|
|
69
67
|
In your view:
|
@@ -13,8 +13,7 @@ module Ransack
|
|
13
13
|
|
14
14
|
def evaluate(search, opts = {})
|
15
15
|
viz = Visitor.new
|
16
|
-
|
17
|
-
opts[:distinct] ? relation.select("DISTINCT #{@klass.quoted_table_name}.*") : relation
|
16
|
+
@object.where(viz.accept(search.base)).order(viz.accept(search.sorts))
|
18
17
|
end
|
19
18
|
|
20
19
|
def attribute_method?(str, klass = @klass)
|
@@ -5,7 +5,7 @@ module Ransack
|
|
5
5
|
|
6
6
|
def self.extended(base)
|
7
7
|
alias :search :ransack unless base.method_defined? :search
|
8
|
-
base.
|
8
|
+
base.class_eval do
|
9
9
|
class_attribute :_ransackers
|
10
10
|
self._ransackers ||= {}
|
11
11
|
end
|
@@ -16,7 +16,7 @@ module Ransack
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def ransacker(name, opts = {}, &block)
|
19
|
-
Ransacker.new(self, name, opts, &block)
|
19
|
+
self._ransackers = _ransackers.merge name.to_s => Ransacker.new(self, name, opts, &block)
|
20
20
|
end
|
21
21
|
|
22
22
|
def ransackable_attributes(auth_object = nil)
|
@@ -11,8 +11,7 @@ module Ransack
|
|
11
11
|
|
12
12
|
def evaluate(search, opts = {})
|
13
13
|
viz = Visitor.new
|
14
|
-
|
15
|
-
opts[:distinct] ? relation.select("DISTINCT #{@klass.quoted_table_name}.*") : relation
|
14
|
+
@object.where(viz.accept(search.base)).order(viz.accept(search.sorts))
|
16
15
|
end
|
17
16
|
|
18
17
|
def attribute_method?(str, klass = @klass)
|
data/lib/ransack/ransacker.rb
CHANGED
data/lib/ransack/version.rb
CHANGED
data/spec/ransack/search_spec.rb
CHANGED
@@ -129,12 +129,6 @@ module Ransack
|
|
129
129
|
where.to_sql.should match /\("people"."name" = 'Ernie' OR "children_people"."name" = 'Ernie'\) AND \("people"."name" = 'Bert' OR "children_people"."name" = 'Bert'\)/
|
130
130
|
end
|
131
131
|
|
132
|
-
it 'returns distinct records when passed :distinct => true' do
|
133
|
-
search = Search.new(Person, :g => [{:m => 'or', :comments_body_cont => 'e', :articles_comments_body_cont => 'e'}])
|
134
|
-
search.result.should have(920).items
|
135
|
-
search.result(:distinct => true).should have(330).items
|
136
|
-
search.result.all.uniq.should eq search.result(:distinct => true).all
|
137
|
-
end
|
138
132
|
end
|
139
133
|
|
140
134
|
describe '#sorts=' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ransack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-06-
|
12
|
+
date: 2011-06-10 00:00:00.000000000 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
17
|
-
requirement: &
|
17
|
+
requirement: &2153569220 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '3.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2153569220
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: activesupport
|
28
|
-
requirement: &
|
28
|
+
requirement: &2153568300 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '3.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2153568300
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: actionpack
|
39
|
-
requirement: &
|
39
|
+
requirement: &2153567660 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '3.0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2153567660
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rspec
|
50
|
-
requirement: &
|
50
|
+
requirement: &2153567060 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: 2.5.0
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2153567060
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: machinist
|
61
|
-
requirement: &
|
61
|
+
requirement: &2153566460 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ~>
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: 1.0.6
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *2153566460
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: faker
|
72
|
-
requirement: &
|
72
|
+
requirement: &2153565840 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: 0.9.5
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *2153565840
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: sqlite3
|
83
|
-
requirement: &
|
83
|
+
requirement: &2153565180 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ~>
|
@@ -88,7 +88,7 @@ dependencies:
|
|
88
88
|
version: 1.3.3
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *2153565180
|
92
92
|
description: Ransack is the successor to the MetaSearch gem. It improves and expands
|
93
93
|
upon MetaSearch's functionality, but does not have a 100%-compatible API.
|
94
94
|
email:
|