nql 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # NQL
2
2
 
3
- [![Build Status](https://travis-ci.org/gabynaiman/nql.png)](https://travis-ci.org/gabynaiman/nql)
3
+ [![Build Status](https://travis-ci.org/gabynaiman/nql.png?branch=master)](https://travis-ci.org/gabynaiman/nql)
4
4
 
5
5
  Natural Query Language built on top of ActiveRecord and Ransack
6
6
 
@@ -394,6 +394,7 @@ module NQL
394
394
  '<' => 'lt',
395
395
  '<=' => 'lteq',
396
396
  ':' => 'cont',
397
+ '!:' => 'not_cont',
397
398
  '~' => 'matches'
398
399
  }
399
400
  comparators[text_value]
@@ -484,18 +485,29 @@ module NQL
484
485
  if r8
485
486
  r1 = r8
486
487
  else
487
- if has_terminal?('~', false, index)
488
- r9 = instantiate_node(SyntaxNode,input, index...(index + 1))
489
- @index += 1
488
+ if has_terminal?('!:', false, index)
489
+ r9 = instantiate_node(SyntaxNode,input, index...(index + 2))
490
+ @index += 2
490
491
  else
491
- terminal_parse_failure('~')
492
+ terminal_parse_failure('!:')
492
493
  r9 = nil
493
494
  end
494
495
  if r9
495
496
  r1 = r9
496
497
  else
497
- @index = i1
498
- r1 = nil
498
+ if has_terminal?('~', false, index)
499
+ r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
500
+ @index += 1
501
+ else
502
+ terminal_parse_failure('~')
503
+ r10 = nil
504
+ end
505
+ if r10
506
+ r1 = r10
507
+ else
508
+ @index = i1
509
+ r1 = nil
510
+ end
499
511
  end
500
512
  end
501
513
  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',
@@ -78,6 +78,7 @@ module NQL
78
78
  '<' => 'lt',
79
79
  '<=' => 'lteq',
80
80
  ':' => 'cont',
81
+ '!:' => 'not_cont',
81
82
  '~' => 'matches'
82
83
  }
83
84
  comparators[text_value]
@@ -1,3 +1,3 @@
1
1
  module NQL
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'spec_helper'
2
3
 
3
4
  describe NQL::SyntaxParser, '-> Comparison' do
@@ -62,6 +63,14 @@ describe NQL::SyntaxParser, '-> Comparison' do
62
63
  tree.comparison.value.text_value.should eq 'value'
63
64
  end
64
65
 
66
+ it 'Not contains' do
67
+ tree = parser.parse('var !: value')
68
+
69
+ tree.comparison.variable.text_value.should eq 'var'
70
+ tree.comparison.comparator.text_value.should eq '!:'
71
+ tree.comparison.value.text_value.should eq 'value'
72
+ end
73
+
65
74
  it 'Matches' do
66
75
  tree = parser.parse('var ~ value')
67
76
 
@@ -135,7 +144,7 @@ describe NQL::SyntaxParser, '-> Comparison' do
135
144
 
136
145
 
137
146
  it 'With utf8 chars and symbols' do
138
- utf8_symbols = "\u00c0\u00c1\u00c2\u00c3\u00c4\u00c7\u00c8\u00c9\u00ca\u00cb\u00cc\u00cd\u00ce\u00cf\u00d1\u00d2\u00d3\u00d4\u00d5\u00d6\u00d9\u00da\u00db\u00dc\u00e0\u00e1\u00e2\u00e3\u00e4\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f9\u00fa\u00fb\u00fc"
147
+ utf8_symbols = "ÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜàáâãäçèéêëìíîïñòóôõöùúûü"
139
148
  tree = parser.parse("var = .#+-#{utf8_symbols}")
140
149
  tree.comparison.value.text_value.should eq ".#+-#{utf8_symbols}"
141
150
  end
@@ -62,6 +62,14 @@ describe 'Ransack Query' do
62
62
  q[:c][0].should have_value '1234'
63
63
  end
64
64
 
65
+ it 'Not contains' 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 'not_cont'
70
+ q[:c][0].should have_value '1234'
71
+ end
72
+
65
73
  it 'Matches' do
66
74
  q = parser.parse('id ~ 1234').to_ransack
67
75
 
@@ -45,6 +45,11 @@ describe 'SQL generation' do
45
45
  Country.nql(q).should produce_sql "SELECT \"countries\".* FROM \"countries\" WHERE (\"countries\".\"name\" LIKE '%abcd%')"
46
46
  end
47
47
 
48
+ it 'Not contains' do
49
+ q = 'name !: abcd'
50
+ Country.nql(q).should produce_sql "SELECT \"countries\".* FROM \"countries\" WHERE (\"countries\".\"name\" NOT LIKE '%abcd%')"
51
+ end
52
+
48
53
  it 'Matches' do
49
54
  q = 'name ~ abcd'
50
55
  Country.nql(q).should produce_sql "SELECT \"countries\".* FROM \"countries\" WHERE (\"countries\".\"name\" LIKE 'abcd')"
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.1.0
4
+ version: 0.1.1
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: 2013-02-28 00:00:00.000000000 Z
12
+ date: 2013-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: treetop