Class: StorageRoom::Collection
- Defined in:
- lib/storage_room/models/collection.rb
Overview
A collection is used to define the structure of a data set.
Instance Attribute Summary
Attributes inherited from Model
Class Method Summary collapse
-
.index_path ⇒ Object
:nodoc:.
-
.json_name ⇒ Object
:nodoc:.
-
.show_path(collection_id) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#association_fields ⇒ Object
All fields of type AssociationField.
-
#deleted_entries ⇒ Object
Load all deleted entries of a collection.
-
#entries ⇒ Object
Load all the entries of a collection.
-
#entry_class ⇒ Object
The class for the collection’s entries.
-
#entry_class_name ⇒ Object
The class name of the collection’s entries, can be overridden with a mapping.
-
#field(identifier) ⇒ Object
The field with a specific identifier.
-
#load_associated_collections ⇒ Object
Load all Collections that are related to the current one through AssociationFields.
Methods inherited from Model
all, create, #create, #destroy, #errors, find, #initialize, #new_record?, #reset!, #save, #to_hash, #update, #valid?
Methods inherited from Resource
handle_critical_response_errors, #loaded?, meta_data?, #reload
Methods included from Plugins
Methods included from Accessors
#[], #as_json, #attributes, #attributes=, #eql?, #hash, #initialize, #inspect, #loaded?, #proxy?, #reset!, #response_data, #response_data=, #set_from_response_data, #to_hash
Constructor Details
This class inherits a constructor from StorageRoom::Model
Class Method Details
.index_path ⇒ Object
:nodoc:
13 14 15 |
# File 'lib/storage_room/models/collection.rb', line 13 def index_path # :nodoc: "#{Resource.base_uri}/collections" end |
.json_name ⇒ Object
:nodoc:
21 22 23 |
# File 'lib/storage_room/models/collection.rb', line 21 def json_name # :nodoc: 'collection' end |
.show_path(collection_id) ⇒ Object
:nodoc:
17 18 19 |
# File 'lib/storage_room/models/collection.rb', line 17 def show_path(collection_id) # :nodoc: "#{index_path}/#{collection_id}" end |
Instance Method Details
#association_fields ⇒ Object
All fields of type AssociationField
62 63 64 |
# File 'lib/storage_room/models/collection.rb', line 62 def association_fields fields.select{|f| f.is_a?(AssociationField)} end |
#deleted_entries ⇒ Object
Load all deleted entries of a collection
46 47 48 |
# File 'lib/storage_room/models/collection.rb', line 46 def deleted_entries Array.load(self[:@deleted_entries_url]) end |
#entries ⇒ Object
Load all the entries of a collection
39 40 41 42 43 |
# File 'lib/storage_room/models/collection.rb', line 39 def entries require_initialized_entry_class do Array.load(self[:@entries_url]) end end |
#entry_class ⇒ Object
The class for the collection’s entries
32 33 34 35 36 |
# File 'lib/storage_room/models/collection.rb', line 32 def entry_class require_initialized_entry_class do self.entry_class_name.constantize end end |
#entry_class_name ⇒ Object
The class name of the collection’s entries, can be overridden with a mapping
27 28 29 |
# File 'lib/storage_room/models/collection.rb', line 27 def entry_class_name ensure_loaded { StorageRoom.entry_class_for_name(entry_type)} end |
#field(identifier) ⇒ Object
The field with a specific identifier
51 52 53 54 55 56 57 58 59 |
# File 'lib/storage_room/models/collection.rb', line 51 def field(identifier) ensure_loaded do fields.each do |f| return f if f.identifier == identifier end end nil end |
#load_associated_collections ⇒ Object
Load all Collections that are related to the current one through AssociationFields
67 68 69 70 71 72 73 74 |
# File 'lib/storage_room/models/collection.rb', line 67 def load_associated_collections array = association_fields if array.map{|f| f.collection_loaded?}.include?(false) StorageRoom.log("Fetching associated collections for '#{name}'") array.each{|f| f.collection} end end |