wherewolf 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ./
3
3
  specs:
4
- wherewolf (0.2.0)
4
+ wherewolf (0.3.0)
5
5
  arel
6
6
  parslet
7
7
 
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.2.0"
25
+ gem.version = "0.3.0"
26
26
  # dependencies defined in Gemfile
27
27
  end
28
28
  Jeweler::RubygemsDotOrgTasks.new
@@ -32,33 +32,48 @@ protected
32
32
  end
33
33
 
34
34
  def process_eq(ast, table)
35
+ check_column!(ast[:left], table)
35
36
  table[ast[:left].to_sym].eq(parse_value(ast[:right]))
36
37
  end
37
38
 
38
39
  def process_not_eq(ast, table)
40
+ check_column!(ast[:left], table)
39
41
  table[ast[:left].to_sym].not_eq(parse_value(ast[:right]))
40
42
  end
41
43
 
42
44
  def process_matches(ast, table)
45
+ check_column!(ast[:left], table)
43
46
  table[ast[:left].to_sym].matches(parse_value(ast[:right]))
44
47
  end
45
48
 
46
49
  def process_lt(ast, table)
50
+ check_column!(ast[:left], table)
47
51
  table[ast[:left].to_sym].lt(parse_value(ast[:right]))
48
52
  end
49
53
 
50
54
  def process_lteq(ast, table)
55
+ check_column!(ast[:left], table)
51
56
  table[ast[:left].to_sym].lteq(parse_value(ast[:right]))
52
57
  end
53
58
 
54
59
  def process_gt(ast, table)
60
+ check_column!(ast[:left], table)
55
61
  table[ast[:left].to_sym].gt(parse_value(ast[:right]))
56
62
  end
57
63
 
58
64
  def process_gteq(ast, table)
65
+ check_column!(ast[:left], table)
59
66
  table[ast[:left].to_sym].gteq(parse_value(ast[:right]))
60
67
  end
61
68
 
69
+ def check_column!(value, table)
70
+ unless table.columns.map(&:name).include?(value.to_sym)
71
+ source = Parslet::Source.new(value.to_s)
72
+ cause = Parslet::Cause.new('Column not found', source, value.offset, [])
73
+ raise Parslet::ParseFailed.new('Column not found', cause)
74
+ end
75
+ end
76
+
62
77
  def parse_value(value)
63
78
  type = value.keys.first
64
79
  case type
@@ -41,7 +41,6 @@ class ProcessorTest < Test::Unit::TestCase
41
41
  assert_equal 28, e.position
42
42
  end
43
43
  end
44
-
45
44
 
46
45
  should 'show a nice debug error' do
47
46
  begin
@@ -58,7 +57,20 @@ class ProcessorTest < Test::Unit::TestCase
58
57
  assert_equal "Parsing error occured at character 28", e.to_s
59
58
  end
60
59
  end
60
+
61
+ should 'be raised if the requested column is not in the list' do
62
+ assert_raise Wherewolf::ParseError do
63
+ Player.from_query('shoe_size > 10')
64
+ end
65
+ end
61
66
 
67
+ should 'show a nice debug error if the requested column is not in the list' do
68
+ begin
69
+ Player.from_query('shoe_size > 10')
70
+ rescue Wherewolf::ParseError => e
71
+ assert_equal "Parsing error occured at character 0", e.to_s
72
+ end
73
+ end
62
74
  end
63
75
 
64
76
  should 'construct simple boolean statements' do
data/wherewolf.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "wherewolf"
8
- s.version = "0.2.0"
8
+ s.version = "0.3.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"]
12
- s.date = "2012-10-10"
12
+ s.date = "2012-10-11"
13
13
  s.description = "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."
14
14
  s.email = "myles@madpilot.com.au"
15
15
  s.extra_rdoc_files = [
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.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-10 00:00:00.000000000 Z
12
+ date: 2012-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: arel
16
- requirement: &70166778516180 !ruby/object:Gem::Requirement
16
+ requirement: &70231215234580 !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: *70166778516180
24
+ version_requirements: *70231215234580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: parslet
27
- requirement: &70166778514340 !ruby/object:Gem::Requirement
27
+ requirement: &70231215233400 !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: *70166778514340
35
+ version_requirements: *70231215233400
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: shoulda
38
- requirement: &70166778512340 !ruby/object:Gem::Requirement
38
+ requirement: &70231215232100 !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: *70166778512340
46
+ version_requirements: *70231215232100
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &70166778511320 !ruby/object:Gem::Requirement
49
+ requirement: &70231215230020 !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: *70166778511320
57
+ version_requirements: *70231215230020
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &70166778510520 !ruby/object:Gem::Requirement
60
+ requirement: &70231215244520 !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: *70166778510520
68
+ version_requirements: *70231215244520
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jeweler
71
- requirement: &70166778509620 !ruby/object:Gem::Requirement
71
+ requirement: &70231215243640 !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: *70166778509620
79
+ version_requirements: *70231215243640
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: guard
82
- requirement: &70166778525100 !ruby/object:Gem::Requirement
82
+ requirement: &70231215242880 !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: *70166778525100
90
+ version_requirements: *70231215242880
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: guard-test
93
- requirement: &70166778524220 !ruby/object:Gem::Requirement
93
+ requirement: &70231215242000 !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: *70166778524220
101
+ version_requirements: *70231215242000
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: simplecov
104
- requirement: &70166778522920 !ruby/object:Gem::Requirement
104
+ requirement: &70231215240760 !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: *70166778522920
112
+ version_requirements: *70231215240760
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: sqlite3
115
- requirement: &70166778521500 !ruby/object:Gem::Requirement
115
+ requirement: &70231215239680 !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: *70166778521500
123
+ version_requirements: *70231215239680
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: rails
126
- requirement: &70166778520140 !ruby/object:Gem::Requirement
126
+ requirement: &70231215238260 !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: *70166778520140
134
+ version_requirements: *70231215238260
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: wherewolf
137
- requirement: &70166778519320 !ruby/object:Gem::Requirement
137
+ requirement: &70231215253700 !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: *70166778519320
145
+ version_requirements: *70231215253700
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.
@@ -186,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  segments:
188
188
  - 0
189
- hash: -122893438368244231
189
+ hash: 730622563305472605
190
190
  required_rubygems_version: !ruby/object:Gem::Requirement
191
191
  none: false
192
192
  requirements: