Class: DeadSimpleCMS::Attribute::Collection
- Inherits:
-
Object
- Object
- DeadSimpleCMS::Attribute::Collection
- Includes:
- Util::Identifier
- Defined in:
- lib/dead_simple_cms/attribute/collection.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
- #add_attribute(attribute) ⇒ Object
-
#initialize(identifier, options = {}) ⇒ Collection
constructor
A new instance of Collection.
-
#persisted? ⇒ Boolean
Play nicely with Rails fields_for.
- #update_attributes(attributes) ⇒ Object
Constructor Details
#initialize(identifier, options = {}) ⇒ Collection
Returns a new instance of Collection.
14 15 16 17 |
# File 'lib/dead_simple_cms/attribute/collection.rb', line 14 def initialize(identifier, ={}) @attributes = Attribute::Type::Base.new_dictionary(:identifier_method => dictionary_identifier_method) super end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/dead_simple_cms/attribute/collection.rb', line 6 def attributes @attributes end |
Instance Method Details
#add_attribute(attribute) ⇒ Object
43 44 45 46 |
# File 'lib/dead_simple_cms/attribute/collection.rb', line 43 def add_attribute(attribute) attributes.add(attribute) attribute_accessor(attribute) end |
#persisted? ⇒ Boolean
Play nicely with Rails fields_for.
20 21 22 |
# File 'lib/dead_simple_cms/attribute/collection.rb', line 20 def persisted? false end |
#update_attributes(attributes) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/dead_simple_cms/attribute/collection.rb', line 24 def update_attributes(attributes) # Sometimes we have to do initial preparing of attributes, before sending them to updating. # For example, if we use select_datetime from Rails, it creates many fields in params, so the resulting # params may look like: # # {'foo' => 'bar', 'date(1i)' => '2000', 'date(2i)' => '10', 'date(3i)' => '30'} # # Of course we have to modify it to put everything into the same key, like: # # {'foo' => 'bar', 'date' => '2000-10-30'} # # or something like that. So, if your attribute type requires such transformations, please specify # .convert_attributes method in it. Configuration.attribute_classes.each do |klass| klass.convert_attributes(attributes) if klass.respond_to?(:convert_attributes) end attributes.each { |k, v| send("#{k}=", v) } end |