nql 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2425f04ebb2fc216c2026f10a69d644162249f7dd0cc76ceacebd71c0f266603
4
+ data.tar.gz: c0616e9d0f4ed6fea53b8669420dee4054475e3287fbdfa601f011f3f549de0f
5
+ SHA512:
6
+ metadata.gz: 8272a744a3a6786c1549d237937ab05815cc543440f3561897fdaee1c96d451ade59f14d4e4e56d1669073ebc00a22bc4fa0afc11d65cb1eab6d3dffff1de723
7
+ data.tar.gz: b93e13fe0b17a89c1ea394b0e50f0b3bf3c7e3c9a7523c2b21013b560968ef92a5ce704c9cf983c6b17076101ee78ec3deb342ed429d5c71e0c147603f5edbc9
@@ -0,0 +1,2 @@
1
+ service_name: travis-ci
2
+ repo_token: tyUx6a4cZK6H9VorUnDSz798WfDILLXUb
@@ -0,0 +1 @@
1
+ nql
@@ -0,0 +1 @@
1
+ ruby-2.5.0
@@ -1,5 +1,22 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
- - 1.9.2
4
- - 1.9.3
5
- script: bundle exec rspec spec
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
7
+ - 2.3
8
+ - 2.4
9
+ - 2.5
10
+ - 2.6
11
+ - 2.7
12
+ - jruby-9.2.9.0
13
+ - ruby-head
14
+ - jruby-head
15
+
16
+ matrix:
17
+ fast_finish: true
18
+ allow_failures:
19
+ - rvm: 2.7
20
+ - rvm: jruby-9.2.9.0
21
+ - rvm: ruby-head
22
+ - rvm: jruby-head
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in nql.gemspec
4
4
  gemspec
5
+
6
+ gem 'coveralls', require: false
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # NQL
2
2
 
3
- [![Build Status](https://travis-ci.org/gabynaiman/nql.png?branch=master)](https://travis-ci.org/gabynaiman/nql)
3
+ [![Gem Version](https://badge.fury.io/rb/nql.svg)](https://rubygems.org/gems/nql)
4
+ [![Build Status](https://travis-ci.org/gabynaiman/nql.svg?branch=master)](https://travis-ci.org/gabynaiman/nql)
5
+ [![Coverage Status](https://coveralls.io/repos/gabynaiman/nql/badge.svg?branch=master)](https://coveralls.io/r/gabynaiman/nql?branch=master)
6
+ [![Code Climate](https://codeclimate.com/github/gabynaiman/nql.svg)](https://codeclimate.com/github/gabynaiman/nql)
4
7
 
5
8
  Natural Query Language built on top of ActiveRecord and Ransack
6
9
 
@@ -24,6 +27,7 @@ Or install it yourself as:
24
27
  | Symbol | Description |
25
28
  --------------------------------------
26
29
  | : | Contains |
30
+ | !: | Not contains |
27
31
  | = | Equals |
28
32
  | != | Not equals |
29
33
  | > | Grater than |
data/Rakefile CHANGED
@@ -1,2 +1,10 @@
1
- #!/usr/bin/env rake
2
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new do |task|
5
+ task.pattern = 'spec/**/*_spec.rb'
6
+ task.rspec_opts = '--tty --color -f documentation'
7
+ task.verbose = false
8
+ end
9
+
10
+ task default: :spec
data/lib/nql.rb CHANGED
@@ -6,6 +6,7 @@ require 'ransack'
6
6
  require 'nql/version'
7
7
  require 'nql/extension/hash'
8
8
  require 'nql/extension/active_record'
9
+ require 'nql/extension/arel'
9
10
  require 'nql/grammar'
10
11
  require 'nql/query'
11
12
  require 'nql/error'
@@ -0,0 +1,7 @@
1
+ module Arel
2
+ module Visitors
3
+ class ToSql
4
+ alias :visit_Integer :literal
5
+ end
6
+ end
7
+ end
@@ -145,7 +145,7 @@ module NQL
145
145
  elements[1]
146
146
  end
147
147
 
148
- def expression
148
+ def comparison
149
149
  elements[2]
150
150
  end
151
151
 
@@ -156,6 +156,21 @@ module NQL
156
156
  end
157
157
 
158
158
  module Primary2
159
+ def space1
160
+ elements[1]
161
+ end
162
+
163
+ def expression
164
+ elements[2]
165
+ end
166
+
167
+ def space2
168
+ elements[3]
169
+ end
170
+
171
+ end
172
+
173
+ module Primary3
159
174
  def to_ransack
160
175
  detect_node.to_ransack
161
176
  end
@@ -201,7 +216,7 @@ module NQL
201
216
  end
202
217
  if r1
203
218
  r0 = r1
204
- r0.extend(Primary2)
219
+ r0.extend(Primary3)
205
220
  else
206
221
  i5, s5 = index, []
207
222
  if has_terminal?('(', false, index)
@@ -216,7 +231,7 @@ module NQL
216
231
  r7 = _nt_space
217
232
  s5 << r7
218
233
  if r7
219
- r8 = _nt_expression
234
+ r8 = _nt_comparison
220
235
  s5 << r8
221
236
  if r8
222
237
  r9 = _nt_space
@@ -243,10 +258,53 @@ module NQL
243
258
  end
244
259
  if r5
245
260
  r0 = r5
246
- r0.extend(Primary2)
261
+ r0.extend(Primary3)
247
262
  else
248
- @index = i0
249
- r0 = nil
263
+ i11, s11 = index, []
264
+ if has_terminal?('(', false, index)
265
+ r12 = instantiate_node(SyntaxNode,input, index...(index + 1))
266
+ @index += 1
267
+ else
268
+ terminal_parse_failure('(')
269
+ r12 = nil
270
+ end
271
+ s11 << r12
272
+ if r12
273
+ r13 = _nt_space
274
+ s11 << r13
275
+ if r13
276
+ r14 = _nt_expression
277
+ s11 << r14
278
+ if r14
279
+ r15 = _nt_space
280
+ s11 << r15
281
+ if r15
282
+ if has_terminal?(')', false, index)
283
+ r16 = instantiate_node(SyntaxNode,input, index...(index + 1))
284
+ @index += 1
285
+ else
286
+ terminal_parse_failure(')')
287
+ r16 = nil
288
+ end
289
+ s11 << r16
290
+ end
291
+ end
292
+ end
293
+ end
294
+ if s11.last
295
+ r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
296
+ r11.extend(Primary2)
297
+ else
298
+ @index = i11
299
+ r11 = nil
300
+ end
301
+ if r11
302
+ r0 = r11
303
+ r0.extend(Primary3)
304
+ else
305
+ @index = i0
306
+ r0 = nil
307
+ end
250
308
  end
251
309
  end
252
310
 
@@ -29,7 +29,7 @@ module NQL
29
29
  end
30
30
 
31
31
  rule primary
32
- (space comparison space / '(' space expression space ')') {
32
+ (space comparison space / '(' space comparison space ')' / '(' space expression space ')') {
33
33
  def to_ransack
34
34
  detect_node.to_ransack
35
35
  end
@@ -1,3 +1,3 @@
1
1
  module NQL
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -15,11 +15,13 @@ Gem::Specification.new do |s|
15
15
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
16
  s.require_paths = ["lib"]
17
17
 
18
- s.add_dependency 'treetop', '~> 1.4'
18
+ s.add_dependency 'treetop', '~> 1.4.0'
19
19
  s.add_dependency 'activerecord', '>= 3.2.0'
20
20
  s.add_dependency 'activesupport', '>= 3.2.0'
21
21
  s.add_dependency 'ransack', '~> 0.7'
22
22
 
23
- s.add_development_dependency 'sqlite3'
24
- s.add_development_dependency 'rspec'
23
+ s.add_development_dependency 'rake'
24
+ s.add_development_dependency 'sqlite3', '~> 1.3.0'
25
+ s.add_development_dependency 'rspec', '~> 3.0'
26
+ s.add_development_dependency 'simplecov'
25
27
  end
@@ -0,0 +1,8 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start
@@ -2,7 +2,7 @@ class CreateCountries < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :countries do |t|
4
4
  t.string :name, null: false
5
-
5
+ t.boolean :landlocked, null: true
6
6
  t.timestamps
7
7
  end
8
8
  end
@@ -80,7 +80,20 @@ describe 'Ransack Query' do
80
80
 
81
81
  it 'Model references' do
82
82
  q = parser.parse('models.id = 1234').to_ransack
83
+ q[:c][0].should have_attribute 'models_id'
84
+ q[:c][0].should have_predicate 'eq'
85
+ q[:c][0].should have_value '1234'
86
+ end
87
+
88
+ it 'Single comparison with parentheses and spaces' do
89
+ q = parser.parse('( models.id = 1234 )').to_ransack
90
+ q[:c][0].should have_attribute 'models_id'
91
+ q[:c][0].should have_predicate 'eq'
92
+ q[:c][0].should have_value '1234'
93
+ end
83
94
 
95
+ it 'Single comparison with parentheses' do
96
+ q = parser.parse('(models.id = 1234)').to_ransack
84
97
  q[:c][0].should have_attribute 'models_id'
85
98
  q[:c][0].should have_predicate 'eq'
86
99
  q[:c][0].should have_value '1234'
@@ -1,3 +1,4 @@
1
+ require 'coverage_helper'
1
2
  require 'nql'
2
3
 
3
4
  Dir["#{File.dirname(__FILE__)}/models/**/*.rb"].each {|f| require f}
@@ -15,6 +15,18 @@ describe 'SQL generation' do
15
15
  Country.nql(q).should produce_sql "SELECT \"countries\".* FROM \"countries\" WHERE \"countries\".\"name\" = 'abcd'"
16
16
  end
17
17
 
18
+ it 'With parentheses' do
19
+ q = '(name = abcd)'
20
+ a = Country.nql(q)
21
+ a.should produce_sql "SELECT \"countries\".* FROM \"countries\" WHERE \"countries\".\"name\" = 'abcd'"
22
+ end
23
+
24
+ it 'With parentheses and boolean value' do
25
+ q = '(landlocked = true)'
26
+ a = Country.nql(q)
27
+ a.should produce_sql "SELECT \"countries\".* FROM \"countries\" WHERE \"countries\".\"landlocked\" = 't'"
28
+ end
29
+
18
30
  it 'Not equals' do
19
31
  q = 'name != abcd'
20
32
  Country.nql(q).should produce_sql "SELECT \"countries\".* FROM \"countries\" WHERE (\"countries\".\"name\" != 'abcd')"
metadata CHANGED
@@ -1,110 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 0.1.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Gabriel Naiman
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-16 00:00:00.000000000 Z
11
+ date: 2020-08-25 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: treetop
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '1.4'
19
+ version: 1.4.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '1.4'
26
+ version: 1.4.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: activerecord
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: 3.2.0
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: 3.2.0
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: activesupport
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: 3.2.0
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: 3.2.0
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: ransack
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ~>
59
+ - - "~>"
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0.7'
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ~>
66
+ - - "~>"
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0.7'
78
69
  - !ruby/object:Gem::Dependency
79
- name: sqlite3
70
+ name: rake
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.3.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.0
94
97
  - !ruby/object:Gem::Dependency
95
98
  name: rspec
96
99
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
100
  requirements:
99
- - - ! '>='
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
100
116
  - !ruby/object:Gem::Version
101
117
  version: '0'
102
118
  type: :development
103
119
  prerelease: false
104
120
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
121
  requirements:
107
- - - ! '>='
122
+ - - ">="
108
123
  - !ruby/object:Gem::Version
109
124
  version: '0'
110
125
  description: Natural Query Language built on top of ActiveRecord and Ransack
@@ -114,8 +129,11 @@ executables: []
114
129
  extensions: []
115
130
  extra_rdoc_files: []
116
131
  files:
117
- - .gitignore
118
- - .travis.yml
132
+ - ".coveralls.yml"
133
+ - ".gitignore"
134
+ - ".ruby-gemset"
135
+ - ".ruby-version"
136
+ - ".travis.yml"
119
137
  - Gemfile
120
138
  - LICENSE
121
139
  - README.md
@@ -123,6 +141,7 @@ files:
123
141
  - lib/nql.rb
124
142
  - lib/nql/error.rb
125
143
  - lib/nql/extension/active_record.rb
144
+ - lib/nql/extension/arel.rb
126
145
  - lib/nql/extension/hash.rb
127
146
  - lib/nql/grammar.rb
128
147
  - lib/nql/grammar.treetop
@@ -131,6 +150,7 @@ files:
131
150
  - nql.gemspec
132
151
  - spec/comparison_parser_spec.rb
133
152
  - spec/coordination_parser_spec.rb
153
+ - spec/coverage_helper.rb
134
154
  - spec/migrations/20121108154439_create_countries.rb
135
155
  - spec/migrations/20121108154508_create_cities.rb
136
156
  - spec/models/city.rb
@@ -141,31 +161,30 @@ files:
141
161
  - spec/sql_spec.rb
142
162
  homepage: https://github.com/gabynaiman/nql
143
163
  licenses: []
164
+ metadata: {}
144
165
  post_install_message:
145
166
  rdoc_options: []
146
167
  require_paths:
147
168
  - lib
148
169
  required_ruby_version: !ruby/object:Gem::Requirement
149
- none: false
150
170
  requirements:
151
- - - ! '>='
171
+ - - ">="
152
172
  - !ruby/object:Gem::Version
153
173
  version: '0'
154
174
  required_rubygems_version: !ruby/object:Gem::Requirement
155
- none: false
156
175
  requirements:
157
- - - ! '>='
176
+ - - ">="
158
177
  - !ruby/object:Gem::Version
159
178
  version: '0'
160
179
  requirements: []
161
- rubyforge_project:
162
- rubygems_version: 1.8.24
180
+ rubygems_version: 3.0.6
163
181
  signing_key:
164
- specification_version: 3
182
+ specification_version: 4
165
183
  summary: Natural Query Language built on top of ActiveRecord and Ransack
166
184
  test_files:
167
185
  - spec/comparison_parser_spec.rb
168
186
  - spec/coordination_parser_spec.rb
187
+ - spec/coverage_helper.rb
169
188
  - spec/migrations/20121108154439_create_countries.rb
170
189
  - spec/migrations/20121108154508_create_cities.rb
171
190
  - spec/models/city.rb
@@ -174,4 +193,3 @@ test_files:
174
193
  - spec/ransack_spec.rb
175
194
  - spec/spec_helper.rb
176
195
  - spec/sql_spec.rb
177
- has_rdoc: