mongoid_oslc 0.1.2 → 0.1.3

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.
@@ -3,31 +3,13 @@ require 'treetop'
3
3
  module Mongoid
4
4
  module Oslc
5
5
  module Grammar
6
- class GrammarNode < Treetop::Runtime::SyntaxNode
6
+ class BinaryDecision < Treetop::Runtime::SyntaxNode
7
7
  def to_mongo_query
8
- elements[0].to_mongo_query
8
+ operand_1.to_mongo_query.deep_merge(operand_2.to_mongo_query)
9
9
  end
10
10
  end
11
11
 
12
- class BinaryDecision < GrammarNode
13
-
14
- def to_mongo_query
15
- operand_1 = elements[0].to_mongo_query
16
- operand_2 = elements[2].to_mongo_query
17
- operand_1.deep_merge(operand_2)
18
- end
19
- end
20
-
21
- class LogicalOperator < GrammarNode
22
- end
23
-
24
- class Field < GrammarNode
25
- def to_mongo_query
26
- text_content
27
- end
28
- end
29
-
30
- class Operator < GrammarNode
12
+ class Operator < Treetop::Runtime::SyntaxNode
31
13
  OPERATORS = {
32
14
  "=" => "$in",
33
15
  "!=" => "$ne",
@@ -38,10 +20,6 @@ module Mongoid
38
20
  "in" => "$in"
39
21
  }
40
22
 
41
- def to_mongo_query
42
- OPERATORS[text_value]
43
- end
44
-
45
23
  def to_mongo_query_with_value(value)
46
24
  if text_value == "="
47
25
  value
@@ -51,49 +29,44 @@ module Mongoid
51
29
  end
52
30
  end
53
31
 
54
- class InOp < GrammarNode
55
- def to_mongo_query
56
- "$in"
57
- end
58
-
32
+ class InOp < Treetop::Runtime::SyntaxNode
59
33
  def to_mongo_query_with_value(value)
60
34
  { "$in" => value }
61
35
  end
62
36
  end
63
37
 
64
- class InVal < GrammarNode
38
+ class InVal < Treetop::Runtime::SyntaxNode
65
39
  def to_mongo_query
66
- # "[\"First\",\"Second\"]" -> ["First", "Second"]
67
- eval text_value
40
+ [first_value.to_mongo_query] + rest_values.elements.map{|comma_and_value| comma_and_value.rest_value.to_mongo_query }
68
41
  end
69
42
  end
70
43
 
71
- class UriRefEsc < GrammarNode
44
+ class UriRefEsc < Treetop::Runtime::SyntaxNode
72
45
  def to_mongo_query
73
46
  # TODO: an angle bracket-delimited URI reference in which > and \ are \-escaped.
74
47
  text_content
75
48
  end
76
49
  end
77
50
 
78
- class BooleanValue < GrammarNode
51
+ class BooleanValue < Treetop::Runtime::SyntaxNode
79
52
  def to_mongo_query
80
53
  text_value == "true"
81
54
  end
82
55
  end
83
56
 
84
- class BlankValue < GrammarNode
57
+ class BlankValue < Treetop::Runtime::SyntaxNode
85
58
  def to_mongo_query
86
59
  nil
87
60
  end
88
61
  end
89
62
 
90
- class DecimalValue < GrammarNode
63
+ class DecimalValue < Treetop::Runtime::SyntaxNode
91
64
  def to_mongo_query
92
65
  text_value.to_f
93
66
  end
94
67
  end
95
68
 
96
- class StringEsc < GrammarNode
69
+ class StringEsc < Treetop::Runtime::SyntaxNode
97
70
  def to_mongo_query
98
71
  value = text_value[1...-1]
99
72
  if value.starts_with?("*") || value.ends_with?("*")
@@ -105,14 +78,13 @@ module Mongoid
105
78
  end
106
79
  end
107
80
 
108
- class Condition < GrammarNode
81
+ class Condition < Treetop::Runtime::SyntaxNode
109
82
  def to_mongo_query
110
- oslc_name = elements[0].text_value
83
+ oslc_name = field_name.text_value
111
84
  field = Mongoid::Oslc.resources.field_name(oslc_name)
112
- value = elements[2].to_mongo_query
85
+ value = field_value.to_mongo_query
113
86
  value = [] if value.nil? && Mongoid::Oslc.resources.is_field_array?(oslc_name)
114
- operator_with_value = elements[1].to_mongo_query_with_value(value)
115
- { field => operator_with_value }
87
+ { field => operator.to_mongo_query_with_value(value) }
116
88
  end
117
89
  end
118
90
  end
@@ -39,11 +39,13 @@ grammar Grammar
39
39
  end
40
40
 
41
41
  rule term
42
- field comparison_op value <Mongoid::Oslc::Grammar::Condition> / field space in_op space? in_val <Mongoid::Oslc::Grammar::Condition>
42
+ field_name:field operator:comparison_op field_value:value <Mongoid::Oslc::Grammar::Condition>
43
+ /
44
+ field_name:field space operator:in_op space? field_value:in_val <Mongoid::Oslc::Grammar::Condition>
43
45
  end
44
46
 
45
47
  rule boolean_op
46
- 'and' <Mongoid::Oslc::Grammar::LogicalOperator>
48
+ 'and'
47
49
  end
48
50
 
49
51
  rule in_op
@@ -51,7 +53,7 @@ grammar Grammar
51
53
  end
52
54
 
53
55
  rule in_val
54
- '[' value (',' value)* ']' <Mongoid::Oslc::Grammar::InVal>
56
+ '[' first_value:value rest_values:(',' rest_value:value)* ']' <Mongoid::Oslc::Grammar::InVal>
55
57
  end
56
58
 
57
59
  rule space
@@ -59,7 +61,7 @@ grammar Grammar
59
61
  end
60
62
 
61
63
  rule field
62
- [\w\:]+ <Mongoid::Oslc::Grammar::Field>
64
+ [\w\:]+
63
65
  end
64
66
 
65
67
  rule comparison_op
@@ -16,18 +16,8 @@ module Mongoid
16
16
  tree = @parser.parse(query)
17
17
  raise Mongoid::Oslc::QueryParsingError.new(query, @parser.index) if tree.nil?
18
18
 
19
- clean_tree(tree)
20
-
21
19
  tree.to_mongo_query
22
20
  end
23
-
24
- private
25
-
26
- def self.clean_tree(root_node)
27
- return if(root_node.elements.nil?)
28
- root_node.elements.delete_if{|node| node.class.name == "Treetop::Runtime::SyntaxNode" }
29
- root_node.elements.each {|node| self.clean_tree(node) }
30
- end
31
21
  end
32
22
  end
33
23
  end
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Oslc
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.3'
4
4
  end
5
5
  end
@@ -17,6 +17,10 @@ describe Mongoid::Oslc::Strategy do
17
17
  parse_query('dcterms:title="requirement"').should eql({title: "requirement"})
18
18
  end
19
19
 
20
+ it "should parse not simple query" do
21
+ parse_query('dcterms:title="requirement" and dcterms:description="desc" and dcterms:creator=blank').should eql({title: "requirement", description: 'desc', creators: []})
22
+ end
23
+
20
24
  it "should parse query with conjunction" do
21
25
  parse_query('dcterms:title="requirement" and dcterms:description="first"').should eql({
22
26
  title: "requirement", description: "first"
@@ -64,7 +68,7 @@ describe Mongoid::Oslc::Strategy do
64
68
  end
65
69
 
66
70
  it "should parse query with array values" do
67
- parse_query('dcterms:title in ["First","Second"]').should eql({title: {"$in"=>["First", "Second"]}})
71
+ parse_query('dcterms:title in ["First","Second",false,blank,+5]').should eql({title: {"$in"=>["First", "Second", false, nil, 5.0]}})
68
72
  end
69
73
 
70
74
  it "should parse query with wild char" do
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.1.2
4
+ version: 0.1.3
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-01-28 00:00:00.000000000 Z
12
+ date: 2013-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -155,7 +155,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  segments:
157
157
  - 0
158
- hash: -3967237591695565408
158
+ hash: 4140121173363015006
159
159
  required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  version: '0'
165
165
  segments:
166
166
  - 0
167
- hash: -3967237591695565408
167
+ hash: 4140121173363015006
168
168
  requirements: []
169
169
  rubyforge_project:
170
170
  rubygems_version: 1.8.24