wherewolf 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.5.0"
25
+ gem.version = "0.6.0"
26
26
  # dependencies defined in Gemfile
27
27
  end
28
28
  Jeweler::RubygemsDotOrgTasks.new
@@ -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
@@ -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
@@ -46,7 +46,8 @@ class AddUsers < ActiveRecord::Migration
46
46
  end
47
47
 
48
48
  create_table :countries do |t|
49
- t.string :team
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
 
@@ -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 { return [ :name, :type ] }).send(:whitelist)
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 { return [ :name, :type ] }).send(:blacklist)
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "wherewolf"
8
- s.version = "0.5.0"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Myles Eftos"]
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.5.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: &70293403498180 !ruby/object:Gem::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: *70293403498180
24
+ version_requirements: *70363111528740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: parslet
27
- requirement: &70293403497160 !ruby/object:Gem::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: *70293403497160
35
+ version_requirements: *70363111528260
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: shoulda
38
- requirement: &70293403496160 !ruby/object:Gem::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: *70293403496160
46
+ version_requirements: *70363111527780
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &70293403495640 !ruby/object:Gem::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: *70293403495640
57
+ version_requirements: *70363111527300
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &70293403494940 !ruby/object:Gem::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: *70293403494940
68
+ version_requirements: *70363111526820
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jeweler
71
- requirement: &70293403451080 !ruby/object:Gem::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: *70293403451080
79
+ version_requirements: *70363111526340
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: guard
82
- requirement: &70293403450480 !ruby/object:Gem::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: *70293403450480
90
+ version_requirements: *70363111525860
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: guard-test
93
- requirement: &70293403449820 !ruby/object:Gem::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: *70293403449820
101
+ version_requirements: *70363111525380
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: simplecov
104
- requirement: &70293403448900 !ruby/object:Gem::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: *70293403448900
112
+ version_requirements: *70363111524900
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: sqlite3
115
- requirement: &70293403448020 !ruby/object:Gem::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: *70293403448020
123
+ version_requirements: *70363111524420
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: rails
126
- requirement: &70293403446960 !ruby/object:Gem::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: *70293403446960
134
+ version_requirements: *70363126234820
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: mocha
137
- requirement: &70293403446380 !ruby/object:Gem::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: *70293403446380
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: -2148443602705417876
195
+ hash: -3222849472552349803
196
196
  required_rubygems_version: !ruby/object:Gem::Requirement
197
197
  none: false
198
198
  requirements: