nql 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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
- @index = i1
487
- r1 = nil
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module NQL
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -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
@@ -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
 
@@ -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
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-14 00:00:00.000000000 Z
12
+ date: 2012-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: treetop