mongoid_oslc 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
1
+ module Mongoid
2
+ module Oslc
3
+ class QuerySyntaxError < Exception
4
+ attr :query
5
+ def initialize(message, query = nil)
6
+ @query = query
7
+ super(message)
8
+ end
9
+ end
10
+
11
+ class QueryParsingError < Exception
12
+ attr :query, :index
13
+ def initialize(query = "", index = 0, message = "")
14
+ @query = query
15
+ @index = index
16
+ super("Parse error at offset: #{@index} #{highlight_error(@query, @index)}")
17
+ end
18
+
19
+ protected
20
+
21
+ def highlight_error(str, index)
22
+ error_str = "\n#{str}\n"
23
+ (index - 1).times { error_str << "-" }
24
+ error_str << "^"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -51,6 +51,23 @@ module Mongoid
51
51
  end
52
52
  end
53
53
 
54
+ class InOp < GrammarNode
55
+ def to_mongo_query
56
+ "$in"
57
+ end
58
+
59
+ def to_mongo_query_with_value(value)
60
+ { "$in" => value }
61
+ end
62
+ end
63
+
64
+ class InVal < GrammarNode
65
+ def to_mongo_query
66
+ # "[\"First\",\"Second\"]" -> ["First", "Second"]
67
+ eval text_value
68
+ end
69
+ end
70
+
54
71
  class UriRefEsc < GrammarNode
55
72
  def to_mongo_query
56
73
  # TODO: an angle bracket-delimited URI reference in which > and \ are \-escaped.
@@ -35,13 +35,21 @@ grammar Grammar
35
35
  end
36
36
 
37
37
  rule term
38
- field comparison_op value <Mongoid::Oslc::Grammar::Condition>
38
+ field comparison_op value <Mongoid::Oslc::Grammar::Condition> / field space in_op space? in_val <Mongoid::Oslc::Grammar::Condition>
39
39
  end
40
40
 
41
41
  rule boolean_op
42
42
  'and' <Mongoid::Oslc::Grammar::LogicalOperator>
43
43
  end
44
44
 
45
+ rule in_op
46
+ 'in' <Mongoid::Oslc::Grammar::InOp>
47
+ end
48
+
49
+ rule in_val
50
+ '[' value (',' value)* ']' <Mongoid::Oslc::Grammar::InVal>
51
+ end
52
+
45
53
  rule space
46
54
  ' '
47
55
  end
@@ -14,7 +14,7 @@ module Mongoid
14
14
  @parser = GrammarParser.new
15
15
 
16
16
  tree = @parser.parse(query)
17
- raise Search::QueryParsingError.new(query, @parser.index) if tree.nil?
17
+ raise Mongoid::Oslc::QueryParsingError.new(query, @parser.index) if tree.nil?
18
18
 
19
19
  clean_tree(tree)
20
20
 
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Oslc
3
- VERSION = '0.0.6'
3
+ VERSION = '0.0.7'
4
4
  end
5
5
  end
data/lib/mongoid/oslc.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'mongoid'
2
2
  require 'mongoid/oslc/config'
3
3
  require 'mongoid/oslc/version'
4
+ require 'mongoid/oslc/exceptions'
4
5
  require 'mongoid/oslc/strategy'
5
6
  require 'active_support/concern'
6
7
 
@@ -36,6 +36,14 @@ describe Mongoid::Oslc::Strategy do
36
36
  parse_query('oslc_cm:closed=false').should eql({"closed"=> false})
37
37
  end
38
38
 
39
+ it "should parse query with one values" do
40
+ parse_query('dcterms:title in ["First"]').should eql({"title"=>{"$in"=>["First"]}})
41
+ end
42
+
43
+ it "should parse query with array values" do
44
+ parse_query('dcterms:title in ["First","Second"]').should eql({"title"=>{"$in"=>["First", "Second"]}})
45
+ end
46
+
39
47
  describe "custom fields" do
40
48
  describe "defined by fields_mapping" do
41
49
  before { Mongoid::Oslc.config.stub(:fields_mapping => {'rtc:frontColor' => 'front_color'}) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_oslc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -111,6 +111,7 @@ files:
111
111
  - Rakefile
112
112
  - lib/mongoid/oslc.rb
113
113
  - lib/mongoid/oslc/config.rb
114
+ - lib/mongoid/oslc/exceptions.rb
114
115
  - lib/mongoid/oslc/grammar.rb
115
116
  - lib/mongoid/oslc/grammar.treetop
116
117
  - lib/mongoid/oslc/strategy.rb
@@ -134,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
135
  version: '0'
135
136
  segments:
136
137
  - 0
137
- hash: -2845718114999846246
138
+ hash: -466769109880562586
138
139
  required_rubygems_version: !ruby/object:Gem::Requirement
139
140
  none: false
140
141
  requirements:
@@ -143,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
144
  version: '0'
144
145
  segments:
145
146
  - 0
146
- hash: -2845718114999846246
147
+ hash: -466769109880562586
147
148
  requirements: []
148
149
  rubyforge_project:
149
150
  rubygems_version: 1.8.24