Class: SimpleAMS::Adapters::AMS
- Inherits:
-
Object
- Object
- SimpleAMS::Adapters::AMS
- Defined in:
- lib/simple_ams/adapters/ams.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Collection
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #as_json ⇒ Object
- #fields ⇒ Object
- #forms ⇒ Object
-
#initialize(document, options = {}) ⇒ AMS
constructor
A new instance of AMS.
- #links ⇒ Object
- #metas ⇒ Object
- #relations ⇒ Object
Constructor Details
#initialize(document, options = {}) ⇒ AMS
Returns a new instance of AMS.
6 7 8 9 |
# File 'lib/simple_ams/adapters/ams.rb', line 6 def initialize(document, = {}) @document = document @options = end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
4 5 6 |
# File 'lib/simple_ams/adapters/ams.rb', line 4 def document @document end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/simple_ams/adapters/ams.rb', line 4 def @options end |
Instance Method Details
#as_json ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/simple_ams/adapters/ams.rb', line 11 def as_json return nil if document.resource.nil? hash = {} hash.merge!(fields) hash.merge!(relations) unless relations.empty? hash.merge!(links: links) unless links.empty? hash.merge!(metas: ) unless .empty? hash.merge!(forms: forms) unless forms.empty? return { document.name => hash } if [:root] hash end |
#fields ⇒ Object
27 28 29 30 31 |
# File 'lib/simple_ams/adapters/ams.rb', line 27 def fields @fields ||= document.fields.each_with_object({}) do |field, hash| hash[field.key] = field.value end end |
#forms ⇒ Object
47 48 49 50 51 |
# File 'lib/simple_ams/adapters/ams.rb', line 47 def forms @forms ||= document.forms.each_with_object({}) do |form, hash| hash[form.name] = form.value end end |
#links ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/simple_ams/adapters/ams.rb', line 33 def links return @links ||= {} if document.links.empty? @links ||= document.links.each_with_object({}) do |link, hash| hash[link.name] = link.value end end |
#metas ⇒ Object
41 42 43 44 45 |
# File 'lib/simple_ams/adapters/ams.rb', line 41 def @metas ||= document..each_with_object({}) do |, hash| hash[.name] = .value end end |
#relations ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/simple_ams/adapters/ams.rb', line 53 def relations return @relations = {} if document.relations.available.empty? @relations ||= document.relations.available.each_with_object({}) do |relation, hash| value = if relation.folder? relation.map { |doc| self.class.new(doc).as_json } else self.class.new(relation).as_json end hash[relation.name] = value end end |