MongoidOslc

Code Climate Dependency Status Build Status

Extension for mongoid to parse oslc.where

Installation

Add this line to your application's Gemfile:

gem 'mongoid_oslc'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mongoid_oslc

Usage

Configure

Add initializer with your configuration.

Mongoid::Oslc.configure do |config|
  config.default_namespaces = [:oslc_custom]
end

Include Mongoid::Oslc module to your document

class Article
  include Mongoid::Document
  include Mongoid::Oslc

  domain    'oslc_cm'
  describe  'http://open-services.net/ns/cm#ChangeRequest'

  oslc_field :title,       type: String, mapping: 'dcterms:title'
  oslc_field :description, type: String, mapping: 'dcterms:description'

end
Article.oslc_where('dcterms:title="First article" and dcterms:description="First article description"')
=> #<Mongoid::Criteria
  selector: {"title"=>"First article", "description"=>"First article description"},
  options:  {},
  class:    Article,
  embedded: false>

Mappings

Mongoid::Oslc.resources.mapping
=> {
  "dcterms:title"=>{
    :name=>:title,
    :value_type=>"http://www.w3.org/2001/XMLSchema#string",
    :read_only=>false,
    :occurs=>"http://open-services.net/ns/core#Zero-or-one",
    :allowed_values=>[],
    :embedded=>false,
    :range=>[]
  },
  "dcterms:description"=>{
    :name=>:description,
    :value_type=>"http://www.w3.org/2001/XMLSchema#string",
    :read_only=>false,
    :occurs=>"http://open-services.net/ns/core#Zero-or-one",
    :allowed_values=>[],
    :embedded=>false,
    :range=>[]
  }
}

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request