Module: Lore::Behaviours::Versioned
- Defined in:
- lib/lore/behaviours/versioned.rb
Overview
Usage:
class My_Model < Lore::Model
extend Lore::Behaviours::Versioned
# ...
version_by :version_number
end
my_model_entity.foo = 'bar'
my_model_entity.commit # Will create a new version
Instance Method Summary collapse
-
#commit ⇒ Object
Overloads commit so it increments the version attribute before saving instance to database and creates a new entity with incremented version instead.
-
#version_by(attrib = :version) ⇒ Object
Defines attribute the version number is stored in.
Instance Method Details
#commit ⇒ Object
Overloads commit so it increments the version attribute before saving instance to database and creates a new entity with incremented version instead.
28 29 30 31 |
# File 'lib/lore/behaviours/versioned.rb', line 28 def commit() set_attribute_value(@version_attr, self.attr[@version_attr].to_i + 1) create(self.attr) end |
#version_by(attrib = :version) ⇒ Object
Defines attribute the version number is stored in. Default is ‘version’.
20 21 22 23 |
# File 'lib/lore/behaviours/versioned.rb', line 20 def version_by(attrib=:version) @version_attr = attrib @version_attr_name = attrib.to_s.split('.')[-1].intern end |