Class: DeadSimpleCMS::Attribute::Collection

Inherits:
Object
  • Object
show all
Includes:
Util::Identifier
Defined in:
lib/dead_simple_cms/attribute/collection.rb

Direct Known Subclasses

Group

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={})
  @attributes = Attribute::Type::Base.new_dictionary(:identifier_method => dictionary_identifier_method)
  super
end

Instance Attribute Details

#attributesObject (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.

Returns:

  • (Boolean)


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