Class: DeadSimpleCMS::Storage::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dead_simple_cms/storage/base.rb

Direct Known Subclasses

Database, Memory, RailsCache, Redis

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#sectionObject (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

#readObject

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_paramObject

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_keyObject

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

#writeObject

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