mongoid_oslc 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mongoid/oslc/config.rb +43 -0
- data/lib/mongoid/oslc/grammar.rb +9 -10
- data/lib/mongoid/oslc/version.rb +1 -1
- data/lib/mongoid/oslc.rb +1 -0
- data/spec/lib/mongoid/oslc/strategy_spec.rb +4 -0
- metadata +5 -4
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'active_support/configurable'
|
2
|
+
|
3
|
+
module Mongoid::Oslc
|
4
|
+
# Configures global settings for Kaminari
|
5
|
+
# Kaminari.configure do |config|
|
6
|
+
# config.default_per_page = 10
|
7
|
+
# end
|
8
|
+
def self.configure(&block)
|
9
|
+
yield @config ||= Mongoid::Oslc::Configuration.new
|
10
|
+
end
|
11
|
+
|
12
|
+
# Global settings for Kaminari
|
13
|
+
def self.config
|
14
|
+
@config
|
15
|
+
end
|
16
|
+
|
17
|
+
# need a Class for 3.0
|
18
|
+
class Configuration #:nodoc:
|
19
|
+
include ActiveSupport::Configurable
|
20
|
+
config_accessor :default_namespace
|
21
|
+
config_accessor :fields_mapping
|
22
|
+
|
23
|
+
def param_name
|
24
|
+
config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
|
25
|
+
end
|
26
|
+
|
27
|
+
# define param_name writer (copied from AS::Configurable)
|
28
|
+
writer, line = 'def param_name=(value); config.param_name = value; end', __LINE__
|
29
|
+
singleton_class.class_eval writer, __FILE__, line
|
30
|
+
class_eval writer, __FILE__, line
|
31
|
+
end
|
32
|
+
|
33
|
+
# this is ugly. why can't we pass the default value to config_accessor...?
|
34
|
+
configure do |config|
|
35
|
+
config.default_namespace = :rtc
|
36
|
+
config.fields_mapping = {
|
37
|
+
"dcterms:title" => "title",
|
38
|
+
"dcterms:description" => "description",
|
39
|
+
"dcterms:created" => "created_at",
|
40
|
+
"oslc_cm:closed" => "closed"
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
data/lib/mongoid/oslc/grammar.rb
CHANGED
@@ -72,7 +72,7 @@ module Mongoid
|
|
72
72
|
|
73
73
|
class Condition < GrammarNode
|
74
74
|
def to_mongo_query
|
75
|
-
field =
|
75
|
+
field = field_for(elements[0].text_value)
|
76
76
|
value = elements[2].to_mongo_query
|
77
77
|
operator_with_value = elements[1].to_mongo_query_with_value(value)
|
78
78
|
{ field => operator_with_value }
|
@@ -80,18 +80,17 @@ module Mongoid
|
|
80
80
|
|
81
81
|
private
|
82
82
|
|
83
|
-
def
|
84
|
-
|
85
|
-
|
83
|
+
def field_for(oslc_field)
|
84
|
+
if oslc_field.start_with?(Mongoid::Oslc.config.default_namespace.to_s)
|
85
|
+
oslc_field.split(":")[1]
|
86
86
|
else
|
87
|
-
|
88
|
-
"dcterms:title" => "title",
|
89
|
-
"dcterms:description" => "description",
|
90
|
-
"dcterms:created" => "created_at",
|
91
|
-
"oslc_cm:closed" => "closed"
|
92
|
-
}
|
87
|
+
fields[oslc_field]
|
93
88
|
end
|
94
89
|
end
|
90
|
+
|
91
|
+
def fields
|
92
|
+
@fields ||= Mongoid::Oslc.config.fields_mapping
|
93
|
+
end
|
95
94
|
end
|
96
95
|
end
|
97
96
|
end
|
data/lib/mongoid/oslc/version.rb
CHANGED
data/lib/mongoid/oslc.rb
CHANGED
@@ -35,5 +35,9 @@ describe Mongoid::Oslc::Strategy do
|
|
35
35
|
it "should parse query with boolean value" do
|
36
36
|
parse_query('oslc_cm:closed=false').should eql({"closed"=> false})
|
37
37
|
end
|
38
|
+
|
39
|
+
it "should parse query with custom namespace" do
|
40
|
+
parse_query('rtc:color="Black"').should eql({"color"=> "Black"})
|
41
|
+
end
|
38
42
|
end
|
39
43
|
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.0.
|
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-10-
|
12
|
+
date: 2012-10-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- README.md
|
111
111
|
- Rakefile
|
112
112
|
- lib/mongoid/oslc.rb
|
113
|
+
- lib/mongoid/oslc/config.rb
|
113
114
|
- lib/mongoid/oslc/grammar.rb
|
114
115
|
- lib/mongoid/oslc/grammar.treetop
|
115
116
|
- lib/mongoid/oslc/strategy.rb
|
@@ -133,7 +134,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
134
|
version: '0'
|
134
135
|
segments:
|
135
136
|
- 0
|
136
|
-
hash:
|
137
|
+
hash: 2130768269382147124
|
137
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
139
|
none: false
|
139
140
|
requirements:
|
@@ -142,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
143
|
version: '0'
|
143
144
|
segments:
|
144
145
|
- 0
|
145
|
-
hash:
|
146
|
+
hash: 2130768269382147124
|
146
147
|
requirements: []
|
147
148
|
rubyforge_project:
|
148
149
|
rubygems_version: 1.8.24
|