module RST::Persistent::Persistentable

The interface for persistent-able objects

Attributes

store[R]

Public Instance Methods

delete() click to toggle source

Remove the object from Store

# File lib/modules/persistent/persistent.rb, line 35
def delete
  self.store -= self
end
id() click to toggle source

Return an unique ID (create one if not exists yet) @return [String] @see KEY_LENGTH

# File lib/modules/persistent/persistent.rb, line 45
def id
  @id ||= SecureRandom::hex(KEY_LENGTH)
end
save() click to toggle source

Save the object to Store

# File lib/modules/persistent/persistent.rb, line 30
def save
  store.update(self)
end
store=(store) click to toggle source

Setter for store-attribute @param [Store] store

# File lib/modules/persistent/persistent.rb, line 52
def store=(store)
  move_store(store)
end

Private Instance Methods

move_store(store) click to toggle source

Move the object to another store @abstract - Moving is not implemented yet, though. The method sets the store-attribute if not set already.

# File lib/modules/persistent/persistent.rb, line 60
def move_store store
  if @store && @store != store
    raise NotImplementedError.new('An object can\'t be moved to another store')
  elsif @store != store
    @store = store
  end
  self.store
end