Class: SimpleAMS::Adapters::AMS::Collection

Inherits:
SimpleAMS::Adapters::AMS show all
Defined in:
lib/simple_ams/adapters/ams.rb

Instance Attribute Summary collapse

Attributes inherited from SimpleAMS::Adapters::AMS

#document

Instance Method Summary collapse

Methods inherited from SimpleAMS::Adapters::AMS

#fields, #forms, #links, #relations

Constructor Details

#initialize(folder, options = {}) ⇒ Collection

Returns a new instance of Collection.



72
73
74
75
76
# File 'lib/simple_ams/adapters/ams.rb', line 72

def initialize(folder, options = {})
  @folder = folder
  @adapter = folder.adapter.value
  @options = options
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



70
71
72
# File 'lib/simple_ams/adapters/ams.rb', line 70

def adapter
  @adapter
end

#folderObject (readonly)

Returns the value of attribute folder.



70
71
72
# File 'lib/simple_ams/adapters/ams.rb', line 70

def folder
  @folder
end

#optionsObject (readonly)

Returns the value of attribute options.



70
71
72
# File 'lib/simple_ams/adapters/ams.rb', line 70

def options
  @options
end

Instance Method Details

#as_jsonObject



78
79
80
81
82
83
84
85
86
87
# File 'lib/simple_ams/adapters/ams.rb', line 78

def as_json
  if options[:root]
    {
      folder.name => documents,
      meta: metas
    }
  else
    documents
  end
end

#documentsObject



89
90
91
92
93
# File 'lib/simple_ams/adapters/ams.rb', line 89

def documents
  return folder.map{|document|
    adapter.new(document).as_json
  } || []
end

#metasObject



95
96
97
98
99
100
# File 'lib/simple_ams/adapters/ams.rb', line 95

def metas
  @metas ||= folder.metas.inject({}){ |hash, meta|
    hash[meta.name] = meta.value
    hash
  }
end