Class: SimpleAMS::Adapters::AMS::Collection
Instance Attribute Summary collapse
#document
Instance Method Summary
collapse
#fields, #forms, #relations
Constructor Details
#initialize(folder, options = {}) ⇒ Collection
69
70
71
72
73
74
|
# File 'lib/simple_ams/adapters/ams.rb', line 69
def initialize(folder, options = {})
super
@folder = folder
@adapter = folder.adapter.value
@options = options
end
|
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
67
68
69
|
# File 'lib/simple_ams/adapters/ams.rb', line 67
def adapter
@adapter
end
|
#folder ⇒ Object
Returns the value of attribute folder.
67
68
69
|
# File 'lib/simple_ams/adapters/ams.rb', line 67
def folder
@folder
end
|
#options ⇒ Object
Returns the value of attribute options.
67
68
69
|
# File 'lib/simple_ams/adapters/ams.rb', line 67
def options
@options
end
|
Instance Method Details
#as_json ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/simple_ams/adapters/ams.rb', line 76
def as_json
if options[:root]
{
folder.name => documents,
meta: metas,
links: links
}
else
documents
end
end
|
#documents ⇒ Object
88
89
90
91
92
|
# File 'lib/simple_ams/adapters/ams.rb', line 88
def documents
folder.map do |document|
adapter.new(document).as_json
end || []
end
|
#links ⇒ Object
100
101
102
103
104
|
# File 'lib/simple_ams/adapters/ams.rb', line 100
def links
@links ||= folder.links.each_with_object({}) do |link, hash|
hash[link.name] = link.value
end
end
|
94
95
96
97
98
|
# File 'lib/simple_ams/adapters/ams.rb', line 94
def metas
@metas ||= folder.metas.each_with_object({}) do |meta, hash|
hash[meta.name] = meta.value
end
end
|