wherewolf 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/Rakefile +1 -1
- data/lib/wherewolf.rb +2 -6
- data/lib/wherewolf/processor.rb +2 -2
- data/test/helper.rb +3 -1
- data/test/processor_test.rb +10 -2
- data/wherewolf.gemspec +1 -1
- metadata +26 -26
data/README.rdoc
CHANGED
@@ -59,7 +59,7 @@ Setting blacklist will remove those columns from the list
|
|
59
59
|
Both whitelist and blacklist can take a proc if you want to lazy evaluate
|
60
60
|
|
61
61
|
class Player < ActiveRecord::Base
|
62
|
-
has_query_parsing :whitelist => proc { |model| model.accessible_attributes }
|
62
|
+
has_query_parsing :whitelist => proc { |model| model.accessible_attributes.map(&:to_sym) }
|
63
63
|
end
|
64
64
|
|
65
65
|
would restrict the searchable columns to those exposed by accessible_attributes
|
data/Rakefile
CHANGED
@@ -22,7 +22,7 @@ Jeweler::Tasks.new do |gem|
|
|
22
22
|
gem.description = %Q{Wherewolf allows you to consume search terms as strings without worrying about database injections. It parses the query and converts it into ARel. It's great for creating filterable REST APIs.}
|
23
23
|
gem.email = "myles@madpilot.com.au"
|
24
24
|
gem.authors = ["Myles Eftos"]
|
25
|
-
gem.version = "0.
|
25
|
+
gem.version = "0.6.0"
|
26
26
|
# dependencies defined in Gemfile
|
27
27
|
end
|
28
28
|
Jeweler::RubygemsDotOrgTasks.new
|
data/lib/wherewolf.rb
CHANGED
@@ -12,15 +12,11 @@ module Wherewolf
|
|
12
12
|
|
13
13
|
module ClassMethods
|
14
14
|
def has_query_parsing(options = {})
|
15
|
-
self.class_eval <<-EOV
|
16
|
-
def self.wherewolf_options
|
17
|
-
#{options}
|
18
|
-
end
|
19
|
-
EOV
|
20
|
-
|
21
15
|
self.class_eval do
|
16
|
+
cattr_accessor :wherewolf_options
|
22
17
|
scope :where_query, lambda { |query| Wherewolf::Where::Processor.parse(self, query) }
|
23
18
|
scope :order_query, lambda { |query| Wherewolf::Order::Processor.parse(self, query) }
|
19
|
+
self.wherewolf_options = options
|
24
20
|
end
|
25
21
|
end
|
26
22
|
end
|
data/lib/wherewolf/processor.rb
CHANGED
@@ -22,13 +22,13 @@ module Wherewolf
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def whitelist
|
25
|
-
return @options[:whitelist].call if @options[:whitelist].is_a?(Proc)
|
25
|
+
return @options[:whitelist].call(self.model) if @options[:whitelist].is_a?(Proc)
|
26
26
|
return @options[:whitelist] if @options[:whitelist]
|
27
27
|
return nil
|
28
28
|
end
|
29
29
|
|
30
30
|
def blacklist
|
31
|
-
return @options[:blacklist].call if @options[:blacklist].is_a?(Proc)
|
31
|
+
return @options[:blacklist].call(self.model) if @options[:blacklist].is_a?(Proc)
|
32
32
|
return @options[:blacklist] if @options[:blacklist]
|
33
33
|
return nil
|
34
34
|
end
|
data/test/helper.rb
CHANGED
@@ -46,7 +46,8 @@ class AddUsers < ActiveRecord::Migration
|
|
46
46
|
end
|
47
47
|
|
48
48
|
create_table :countries do |t|
|
49
|
-
t.string :
|
49
|
+
t.string :name
|
50
|
+
t.string :jersey_color
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
@@ -65,6 +66,7 @@ class Team < ActiveRecord::Base
|
|
65
66
|
end
|
66
67
|
|
67
68
|
class Country < ActiveRecord::Base
|
69
|
+
attr_accessible :name
|
68
70
|
has_query_parsing :whitelist => [ :name ]
|
69
71
|
end
|
70
72
|
|
data/test/processor_test.rb
CHANGED
@@ -43,7 +43,11 @@ class ProcessorTest < Test::Unit::TestCase
|
|
43
43
|
end
|
44
44
|
|
45
45
|
should 'evaluate options[:whitelist] if is a proc' do
|
46
|
-
assert_equal [ :name, :type ], Wherewolf::Processor.new(Player, :whitelist => proc {
|
46
|
+
assert_equal [ :name, :type ], Wherewolf::Processor.new(Player, :whitelist => proc { |model| [ :name, :type ] }).send(:whitelist)
|
47
|
+
end
|
48
|
+
|
49
|
+
should 'pass model into whitelist proc' do
|
50
|
+
assert_equal [ :name, ], Wherewolf::Processor.new(Country, :whitelist => proc { |model| model.accessible_attributes.map(&:to_sym) }).send(:whitelist)
|
47
51
|
end
|
48
52
|
end
|
49
53
|
|
@@ -57,7 +61,11 @@ class ProcessorTest < Test::Unit::TestCase
|
|
57
61
|
end
|
58
62
|
|
59
63
|
should 'evaluate options[:blacklist] if is a proc' do
|
60
|
-
assert_equal [ :name, :type ], Wherewolf::Processor.new(Player, :blacklist => proc {
|
64
|
+
assert_equal [ :name, :type ], Wherewolf::Processor.new(Player, :blacklist => proc { |model| [ :name, :type ] }).send(:blacklist)
|
65
|
+
end
|
66
|
+
|
67
|
+
should 'pass model into blacklist proc' do
|
68
|
+
assert_equal [ :name ], Wherewolf::Processor.new(Country, :blacklist => proc { |model| model.accessible_attributes.map(&:to_sym) }).send(:blacklist)
|
61
69
|
end
|
62
70
|
end
|
63
71
|
end
|
data/wherewolf.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wherewolf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-10-12 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: arel
|
16
|
-
requirement: &
|
16
|
+
requirement: &70363111528740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70363111528740
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: parslet
|
27
|
-
requirement: &
|
27
|
+
requirement: &70363111528260 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70363111528260
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: shoulda
|
38
|
-
requirement: &
|
38
|
+
requirement: &70363111527780 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70363111527780
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rdoc
|
49
|
-
requirement: &
|
49
|
+
requirement: &70363111527300 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70363111527300
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bundler
|
60
|
-
requirement: &
|
60
|
+
requirement: &70363111526820 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70363111526820
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: jeweler
|
71
|
-
requirement: &
|
71
|
+
requirement: &70363111526340 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70363111526340
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: guard
|
82
|
-
requirement: &
|
82
|
+
requirement: &70363111525860 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70363111525860
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: guard-test
|
93
|
-
requirement: &
|
93
|
+
requirement: &70363111525380 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70363111525380
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: simplecov
|
104
|
-
requirement: &
|
104
|
+
requirement: &70363111524900 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70363111524900
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: sqlite3
|
115
|
-
requirement: &
|
115
|
+
requirement: &70363111524420 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70363111524420
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: rails
|
126
|
-
requirement: &
|
126
|
+
requirement: &70363126234820 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *70363126234820
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: mocha
|
137
|
-
requirement: &
|
137
|
+
requirement: &70363126233820 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ! '>='
|
@@ -142,7 +142,7 @@ dependencies:
|
|
142
142
|
version: '0'
|
143
143
|
type: :development
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *70363126233820
|
146
146
|
description: Wherewolf allows you to consume search terms as strings without worrying
|
147
147
|
about database injections. It parses the query and converts it into ARel. It's great
|
148
148
|
for creating filterable REST APIs.
|
@@ -192,7 +192,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
192
192
|
version: '0'
|
193
193
|
segments:
|
194
194
|
- 0
|
195
|
-
hash: -
|
195
|
+
hash: -3222849472552349803
|
196
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
197
|
none: false
|
198
198
|
requirements:
|