Class: DeadSimpleCMS::Storage::Base
- Inherits:
-
Object
- Object
- DeadSimpleCMS::Storage::Base
- Defined in:
- lib/dead_simple_cms/storage/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#section ⇒ Object
readonly
Returns the value of attribute section.
Instance Method Summary collapse
-
#initialize(section) ⇒ Base
constructor
A new instance of Base.
-
#read ⇒ Object
Public: Return a hash of the typed attributes from the data source.
-
#to_param ⇒ Object
Creates a unique string to identify this data.
-
#unique_key ⇒ Object
Public: Unique key for use in the storage mechanism.
-
#write ⇒ Object
Public: Write all the attributes of the section to it’s data source.
Constructor Details
#initialize(section) ⇒ Base
Returns a new instance of Base.
11 12 13 |
# File 'lib/dead_simple_cms/storage/base.rb', line 11 def initialize(section) @section = section end |
Instance Attribute Details
#section ⇒ Object (readonly)
Returns the value of attribute section.
9 10 11 |
# File 'lib/dead_simple_cms/storage/base.rb', line 9 def section @section end |
Instance Method Details
#read ⇒ Object
Public: Return a hash of the typed attributes from the data source.
16 17 18 |
# File 'lib/dead_simple_cms/storage/base.rb', line 16 def read @_cache ||= (value = read_value) ? serializer_class.load(read_value) : {} end |
#to_param ⇒ Object
Creates a unique string to identify this data.
33 34 35 |
# File 'lib/dead_simple_cms/storage/base.rb', line 33 def to_param (value = read_value) ? Digest::MD5.hexdigest(value) : nil end |
#unique_key ⇒ Object
Public: Unique key for use in the storage mechanism.
28 29 30 |
# File 'lib/dead_simple_cms/storage/base.rb', line 28 def unique_key @unique_key ||= section.identifier end |
#write ⇒ Object
Public: Write all the attributes of the section to it’s data source. Returns the attributes_hash.
21 22 23 24 25 |
# File 'lib/dead_simple_cms/storage/base.rb', line 21 def write hash = attributes_hash write_value(serializer_class.dump(hash)) @_cache = hash # set @_cache after the write end |