mongoid_oslc 0.1.0 → 0.1.1
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 +28 -4
- data/lib/mongoid/oslc/grammar.rb +1 -9
- data/lib/mongoid/oslc/resources.rb +8 -0
- data/lib/mongoid/oslc/version.rb +1 -1
- data/spec/lib/mongoid/oslc/strategy_spec.rb +28 -25
- data/spec/lib/mongoid/oslc_spec.rb +2 -0
- metadata +7 -1
data/README.md
CHANGED
@@ -21,8 +21,7 @@ Or install it yourself as:
|
|
21
21
|
Add initializer with your configuration.
|
22
22
|
|
23
23
|
Mongoid::Oslc.configure do |config|
|
24
|
-
config.
|
25
|
-
config.fields_mapping = {'dcterms:title' => 'title', 'dcterms:description' => 'description'}
|
24
|
+
config.default_namespaces = [:rtc]
|
26
25
|
end
|
27
26
|
|
28
27
|
Include Mongoid::Oslc module to your document
|
@@ -31,8 +30,11 @@ Include Mongoid::Oslc module to your document
|
|
31
30
|
include Mongoid::Document
|
32
31
|
include Mongoid::Oslc
|
33
32
|
|
34
|
-
|
35
|
-
|
33
|
+
domain 'oslc_cm'
|
34
|
+
describe 'http://open-services.net/ns/cm#ChangeRequest'
|
35
|
+
|
36
|
+
oslc_field :title, type: String, mapping: 'dcterms:title'
|
37
|
+
oslc_field :description, type: String, mapping: 'dcterms:description'
|
36
38
|
|
37
39
|
end
|
38
40
|
|
@@ -43,6 +45,28 @@ Include Mongoid::Oslc module to your document
|
|
43
45
|
class: Article,
|
44
46
|
embedded: false>
|
45
47
|
|
48
|
+
Mongoid::Oslc.resources.mapping
|
49
|
+
=> {
|
50
|
+
"dcterms:title"=>{
|
51
|
+
:name=>:title,
|
52
|
+
:value_type=>"http://www.w3.org/2001/XMLSchema#string",
|
53
|
+
:read_only=>false,
|
54
|
+
:occurs=>"http://open-services.net/ns/core#Zero-or-one",
|
55
|
+
:allowed_values=>[],
|
56
|
+
:embedded=>false,
|
57
|
+
:range=>[]
|
58
|
+
},
|
59
|
+
"dcterms:description"=>{
|
60
|
+
:name=>:description,
|
61
|
+
:value_type=>"http://www.w3.org/2001/XMLSchema#string",
|
62
|
+
:read_only=>false,
|
63
|
+
:occurs=>"http://open-services.net/ns/core#Zero-or-one",
|
64
|
+
:allowed_values=>[],
|
65
|
+
:embedded=>false,
|
66
|
+
:range=>[]
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
46
70
|
## Contributing
|
47
71
|
|
48
72
|
1. Fork it
|
data/lib/mongoid/oslc/grammar.rb
CHANGED
@@ -107,19 +107,11 @@ module Mongoid
|
|
107
107
|
|
108
108
|
class Condition < GrammarNode
|
109
109
|
def to_mongo_query
|
110
|
-
field =
|
110
|
+
field = Mongoid::Oslc.resources.field_name(elements[0].text_value)
|
111
111
|
value = elements[2].to_mongo_query
|
112
112
|
operator_with_value = elements[1].to_mongo_query_with_value(value)
|
113
113
|
{ field => operator_with_value }
|
114
114
|
end
|
115
|
-
|
116
|
-
private
|
117
|
-
|
118
|
-
def field_for(oslc_field)
|
119
|
-
field = Mongoid::Oslc.resources.mapping[oslc_field].try(:fetch, :name)
|
120
|
-
field ||= oslc_field.split(":")[1] if Mongoid::Oslc.config.default_namespaces.include?(oslc_field.split(":")[0])
|
121
|
-
field
|
122
|
-
end
|
123
115
|
end
|
124
116
|
end
|
125
117
|
end
|
@@ -16,6 +16,14 @@ module Mongoid
|
|
16
16
|
def mapping
|
17
17
|
self.inject({}){|hash, klass| hash.merge(klass[1][:fields]) }
|
18
18
|
end
|
19
|
+
|
20
|
+
def field_name(oslc_name)
|
21
|
+
if Mongoid::Oslc.config.default_namespaces.include?(oslc_name.split(":")[0].to_sym)
|
22
|
+
oslc_name.split(':')[1].to_sym
|
23
|
+
else
|
24
|
+
mapping[oslc_name][:name]
|
25
|
+
end
|
26
|
+
end
|
19
27
|
end
|
20
28
|
end
|
21
29
|
end
|
data/lib/mongoid/oslc/version.rb
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
class MongoDocument
|
4
|
+
include Mongoid::Document
|
5
|
+
include Mongoid::Oslc
|
6
|
+
include Mongoid::Timestamps
|
7
|
+
|
8
|
+
oslc_field :title, type: String, mapping: 'dcterms:title'
|
9
|
+
oslc_field :description, type: String, mapping: 'dcterms:description'
|
10
|
+
oslc_field :closed, type: Boolean,mapping: 'oslc_cm:closed'
|
11
|
+
|
12
|
+
register_oslc_field :created_at, mapping: 'dcterms:created', value_type: 'DateTime'
|
13
|
+
register_oslc_field :updated_at, mapping: 'dcterms:modified', value_type: 'DateTime'
|
14
|
+
|
15
|
+
end
|
16
|
+
|
3
17
|
describe Mongoid::Oslc::Strategy do
|
4
18
|
let(:parser) { Mongoid::Oslc::Strategy }
|
5
19
|
|
@@ -14,69 +28,58 @@ describe Mongoid::Oslc::Strategy do
|
|
14
28
|
describe "#parse" do
|
15
29
|
|
16
30
|
it "should parse simple query" do
|
17
|
-
parse_query('dcterms:title="requirement"').should eql({
|
31
|
+
parse_query('dcterms:title="requirement"').should eql({title: "requirement"})
|
18
32
|
end
|
19
33
|
|
20
34
|
it "should parse query with conjunction" do
|
21
35
|
parse_query('dcterms:title="requirement" and dcterms:description="first"').should eql({
|
22
|
-
|
23
|
-
"description"=>"first"
|
36
|
+
title: "requirement", description: "first"
|
24
37
|
})
|
25
38
|
end
|
26
39
|
|
27
40
|
it "should parse query with other comparison_op" do
|
28
|
-
parse_query('dcterms:created>"2010-04-01"').should eql({
|
41
|
+
parse_query('dcterms:created>"2010-04-01"').should eql({created_at: {"$gt"=>"2010-04-01"}})
|
29
42
|
end
|
30
43
|
|
31
44
|
it "should parse query with not value" do
|
32
|
-
parse_query('dcterms:title!="First"').should eql({
|
45
|
+
parse_query('dcterms:title!="First"').should eql({title: {"$ne" => "First"}})
|
33
46
|
end
|
34
47
|
|
35
48
|
it "should parse query with nil value" do
|
36
|
-
parse_query('dcterms:title=nil').should eql({
|
49
|
+
parse_query('dcterms:title=nil').should eql({title: nil})
|
37
50
|
end
|
38
51
|
|
39
52
|
it "should parse query with empty value" do
|
40
|
-
parse_query('dcterms:title=empty').should eql({
|
53
|
+
parse_query('dcterms:title=empty').should eql({title: []})
|
41
54
|
end
|
42
55
|
|
43
56
|
it "should parse query with decimal value" do
|
44
|
-
parse_query('dcterms:title=+5').should eql({
|
57
|
+
parse_query('dcterms:title=+5').should eql({title: 5.0})
|
45
58
|
end
|
46
59
|
|
47
60
|
it "should parse query with decimal value" do
|
48
|
-
parse_query('dcterms:title=-5.151').should eql({
|
61
|
+
parse_query('dcterms:title=-5.151').should eql({title: -5.151})
|
49
62
|
end
|
50
63
|
|
51
64
|
it "should parse query with boolean value" do
|
52
|
-
parse_query('oslc_cm:closed=true').should eql({
|
65
|
+
parse_query('oslc_cm:closed=true').should eql({closed: true})
|
53
66
|
end
|
54
67
|
|
55
68
|
it "should parse query with boolean value" do
|
56
|
-
parse_query('oslc_cm:closed=false').should eql({
|
69
|
+
parse_query('oslc_cm:closed=false').should eql({closed: false})
|
57
70
|
end
|
58
71
|
|
59
72
|
it "should parse query with one values" do
|
60
|
-
parse_query('dcterms:title in ["First"]').should eql({
|
73
|
+
parse_query('dcterms:title in ["First"]').should eql({title: {"$in"=>["First"]}})
|
61
74
|
end
|
62
75
|
|
63
76
|
it "should parse query with array values" do
|
64
|
-
parse_query('dcterms:title in ["First","Second"]').should eql({
|
77
|
+
parse_query('dcterms:title in ["First","Second"]').should eql({title: {"$in"=>["First", "Second"]}})
|
65
78
|
end
|
66
79
|
|
67
80
|
describe "custom fields" do
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
it "should parse query with custom namesapce" do
|
72
|
-
parse_query('rtc:frontColor="Black"').should eql({"front_color"=> "Black"})
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "not defined by fields_mapping" do
|
77
|
-
it "should parse query with custom namespace" do
|
78
|
-
parse_query('rtc:color="Black"').should eql({"color"=> "Black"})
|
79
|
-
end
|
81
|
+
it "should parse query with custom namespace" do
|
82
|
+
parse_query('rtc:color="Black"').should eql({color: "Black"})
|
80
83
|
end
|
81
84
|
end
|
82
85
|
end
|
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.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -150,12 +150,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
150
|
- - ! '>='
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
+
segments:
|
154
|
+
- 0
|
155
|
+
hash: 3353479294008417306
|
153
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
157
|
none: false
|
155
158
|
requirements:
|
156
159
|
- - ! '>='
|
157
160
|
- !ruby/object:Gem::Version
|
158
161
|
version: '0'
|
162
|
+
segments:
|
163
|
+
- 0
|
164
|
+
hash: 3353479294008417306
|
159
165
|
requirements: []
|
160
166
|
rubyforge_project:
|
161
167
|
rubygems_version: 1.8.24
|