nql 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +12 -11
- data/lib/nql/grammar.rb +15 -3
- data/lib/nql/grammar.treetop +3 -2
- data/lib/nql/version.rb +1 -1
- data/spec/comparison_parser_spec.rb +8 -0
- data/spec/ransack_spec.rb +8 -0
- data/spec/sql_spec.rb +5 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -18,17 +18,18 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Supported comparators
|
20
20
|
|
21
|
-
|
22
|
-
| Symbol | Description
|
23
|
-
|
24
|
-
| : | Contains
|
25
|
-
| = | Equals
|
26
|
-
| != | Not equals
|
27
|
-
| > | Grater than
|
28
|
-
| >= | Grater or equals than
|
29
|
-
| < | Less than
|
30
|
-
| <= | Less or equals than
|
31
|
-
|
21
|
+
--------------------------------------
|
22
|
+
| Symbol | Description |
|
23
|
+
--------------------------------------
|
24
|
+
| : | Contains |
|
25
|
+
| = | Equals |
|
26
|
+
| != | Not equals |
|
27
|
+
| > | Grater than |
|
28
|
+
| >= | Grater or equals than |
|
29
|
+
| < | Less than |
|
30
|
+
| <= | Less or equals than |
|
31
|
+
| ~ | Matches (eq ignore case) |
|
32
|
+
--------------------------------------
|
32
33
|
|
33
34
|
|
34
35
|
## Usage
|
data/lib/nql/grammar.rb
CHANGED
@@ -393,7 +393,8 @@ module NQL
|
|
393
393
|
'>=' => 'gteq',
|
394
394
|
'<' => 'lt',
|
395
395
|
'<=' => 'lteq',
|
396
|
-
':' => 'cont'
|
396
|
+
':' => 'cont',
|
397
|
+
'~' => 'matches'
|
397
398
|
}
|
398
399
|
comparators[text_value]
|
399
400
|
end
|
@@ -483,8 +484,19 @@ module NQL
|
|
483
484
|
if r8
|
484
485
|
r1 = r8
|
485
486
|
else
|
486
|
-
|
487
|
-
|
487
|
+
if has_terminal?('~', false, index)
|
488
|
+
r9 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
489
|
+
@index += 1
|
490
|
+
else
|
491
|
+
terminal_parse_failure('~')
|
492
|
+
r9 = nil
|
493
|
+
end
|
494
|
+
if r9
|
495
|
+
r1 = r9
|
496
|
+
else
|
497
|
+
@index = i1
|
498
|
+
r1 = nil
|
499
|
+
end
|
488
500
|
end
|
489
501
|
end
|
490
502
|
end
|
data/lib/nql/grammar.treetop
CHANGED
@@ -68,7 +68,7 @@ module NQL
|
|
68
68
|
end
|
69
69
|
|
70
70
|
rule comparator
|
71
|
-
('=' / '!=' / '>' / '>=' / '<' / '<=' / ':')+ {
|
71
|
+
('=' / '!=' / '>' / '>=' / '<' / '<=' / ':' / '~')+ {
|
72
72
|
def to_ransack
|
73
73
|
comparators = {
|
74
74
|
'=' => 'eq',
|
@@ -77,7 +77,8 @@ module NQL
|
|
77
77
|
'>=' => 'gteq',
|
78
78
|
'<' => 'lt',
|
79
79
|
'<=' => 'lteq',
|
80
|
-
':' => 'cont'
|
80
|
+
':' => 'cont',
|
81
|
+
'~' => 'matches'
|
81
82
|
}
|
82
83
|
comparators[text_value]
|
83
84
|
end
|
data/lib/nql/version.rb
CHANGED
@@ -62,6 +62,14 @@ describe NQL::SyntaxParser, '-> Comparison' do
|
|
62
62
|
tree.comparison.value.text_value.should eq 'value'
|
63
63
|
end
|
64
64
|
|
65
|
+
it 'Matches' do
|
66
|
+
tree = parser.parse('var ~ value')
|
67
|
+
|
68
|
+
tree.comparison.variable.text_value.should eq 'var'
|
69
|
+
tree.comparison.comparator.text_value.should eq '~'
|
70
|
+
tree.comparison.value.text_value.should eq 'value'
|
71
|
+
end
|
72
|
+
|
65
73
|
end
|
66
74
|
|
67
75
|
context 'Space separators' do
|
data/spec/ransack_spec.rb
CHANGED
@@ -62,6 +62,14 @@ describe 'Ransack Query' do
|
|
62
62
|
q[:c][0].should have_value '1234'
|
63
63
|
end
|
64
64
|
|
65
|
+
it 'Matches' do
|
66
|
+
q = parser.parse('id ~ 1234').to_ransack
|
67
|
+
|
68
|
+
q[:c][0].should have_attribute 'id'
|
69
|
+
q[:c][0].should have_predicate 'matches'
|
70
|
+
q[:c][0].should have_value '1234'
|
71
|
+
end
|
72
|
+
|
65
73
|
it 'Model references' do
|
66
74
|
q = parser.parse('models.id = 1234').to_ransack
|
67
75
|
|
data/spec/sql_spec.rb
CHANGED
@@ -45,6 +45,11 @@ describe 'SQL generation' do
|
|
45
45
|
Country.search(NQL.to_ransack(q)).result.should produce_sql "SELECT \"countries\".* FROM \"countries\" WHERE (\"countries\".\"name\" LIKE '%abcd%')"
|
46
46
|
end
|
47
47
|
|
48
|
+
it 'Matches' do
|
49
|
+
q = 'name ~ abcd'
|
50
|
+
Country.search(NQL.to_ransack(q)).result.should produce_sql "SELECT \"countries\".* FROM \"countries\" WHERE (\"countries\".\"name\" LIKE 'abcd')"
|
51
|
+
end
|
52
|
+
|
48
53
|
end
|
49
54
|
|
50
55
|
context 'Coordinated comparisons' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: treetop
|