mongoid_oslc 0.0.5 → 0.0.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # MongoidOslc
2
2
 
3
- TODO: Write a gem description
3
+ Extension for mongoid to parse oslc.where
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,30 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ Add initializer with your configuration.
22
+
23
+ Mongoid::Oslc.configure do |config|
24
+ config.default_namespace = :rtc
25
+ config.fields_mapping = {'dcterms:title' => 'title', 'dcterms:description' => 'description'}
26
+ end
27
+
28
+ Include Mongoid::Oslc module to your document
29
+
30
+ class Article
31
+ include Mongoid::Document
32
+ include Mongoid::Oslc
33
+
34
+ field :title, type: String
35
+ field :description, type: String
36
+
37
+ end
38
+
39
+ Article.oslc_where('dcterms:title="First article" and dcterms:description="First article description"')
40
+ => #<Mongoid::Criteria
41
+ selector: {"title"=>"First article", "description"=>"First article description"},
42
+ options: {},
43
+ class: Article,
44
+ embedded: false>
22
45
 
23
46
  ## Contributing
24
47
 
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -81,15 +81,9 @@ module Mongoid
81
81
  private
82
82
 
83
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
- else
87
- fields[oslc_field]
88
- end
89
- end
90
-
91
- def fields
92
- @fields ||= Mongoid::Oslc.config.fields_mapping
84
+ field = Mongoid::Oslc.config.fields_mapping[oslc_field]
85
+ field ||= oslc_field.split(":")[1] if oslc_field.start_with?(Mongoid::Oslc.config.default_namespace.to_s)
86
+ field
93
87
  end
94
88
  end
95
89
  end
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Oslc
3
- VERSION = '0.0.5'
3
+ VERSION = '0.0.6'
4
4
  end
5
5
  end
@@ -36,8 +36,20 @@ 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 custom namespace" do
40
- parse_query('rtc:color="Black"').should eql({"color"=> "Black"})
39
+ describe "custom fields" do
40
+ describe "defined by fields_mapping" do
41
+ before { Mongoid::Oslc.config.stub(:fields_mapping => {'rtc:frontColor' => 'front_color'}) }
42
+
43
+ it "should parse query with custom namesapce" do
44
+ parse_query('rtc:frontColor="Black"').should eql({"front_color"=> "Black"})
45
+ end
46
+ end
47
+
48
+ describe "not defined by fields_mapping" do
49
+ it "should parse query with custom namespace" do
50
+ parse_query('rtc:color="Black"').should eql({"color"=> "Black"})
51
+ end
52
+ end
41
53
  end
42
54
  end
43
55
  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.5
4
+ version: 0.0.6
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-22 00:00:00.000000000 Z
12
+ date: 2012-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -134,7 +134,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  segments:
136
136
  - 0
137
- hash: 2130768269382147124
137
+ hash: -2845718114999846246
138
138
  required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  version: '0'
144
144
  segments:
145
145
  - 0
146
- hash: 2130768269382147124
146
+ hash: -2845718114999846246
147
147
  requirements: []
148
148
  rubyforge_project:
149
149
  rubygems_version: 1.8.24