Class: Mongoid::Oslc::Resources
- Inherits:
-
Hash
- Object
- Hash
- Mongoid::Oslc::Resources
- Defined in:
- lib/mongoid/oslc/resources.rb
Instance Method Summary collapse
- #class_for(rdf_type) ⇒ Object
- #domain(rdf_type) ⇒ Object
- #field_name(oslc_name) ⇒ Object
-
#initialize ⇒ Resources
constructor
A new instance of Resources.
- #is_field_array?(oslc_name) ⇒ Boolean
- #mapping ⇒ Object
Constructor Details
#initialize ⇒ Resources
Returns a new instance of Resources.
4 5 6 |
# File 'lib/mongoid/oslc/resources.rb', line 4 def initialize super{|h, k| h[k] = {fields: {}}} end |
Instance Method Details
#class_for(rdf_type) ⇒ Object
8 9 10 |
# File 'lib/mongoid/oslc/resources.rb', line 8 def class_for(rdf_type) self.select{|klass,properties| properties[:describe] == rdf_type}.keys.first end |
#domain(rdf_type) ⇒ Object
12 13 14 |
# File 'lib/mongoid/oslc/resources.rb', line 12 def domain(rdf_type) self[class_for(rdf_type)][:domain] end |
#field_name(oslc_name) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/mongoid/oslc/resources.rb', line 20 def field_name(oslc_name) if custom_field?(oslc_name) oslc_name.split(":")[1].to_sym else mapping[oslc_name][:name] end end |
#is_field_array?(oslc_name) ⇒ Boolean
28 29 30 31 32 33 34 35 |
# File 'lib/mongoid/oslc/resources.rb', line 28 def is_field_array?(oslc_name) if custom_field?(oslc_name) false else occurs = self.mapping[oslc_name][:occurs] occurs == ::Oslc::ZERO_OR_MANY || occurs == ::Oslc::ONE_OR_MANY end end |
#mapping ⇒ Object
16 17 18 |
# File 'lib/mongoid/oslc/resources.rb', line 16 def mapping self.inject({}){|hash, klass| hash.merge(klass[1][:fields]) } end |