Module: VestalVersions::Control::ClassMethods

Defined in:
lib/vestal_versions/control.rb

Instance Method Summary collapse

Instance Method Details

#_with_version_flag(flag) ⇒ Object

Used for each control block, the with_version_flag method sets a given variable to true and then executes the given block, ensuring that the variable is returned to a nil value before returning. This is useful to be certain that one of the control flag instance variables isn’t inadvertently left in the “on” position by execution within the block raising an exception.



190
191
192
193
194
195
# File 'lib/vestal_versions/control.rb', line 190

def _with_version_flag(flag)
  self.send("#{flag}=", true)
  yield
ensure
  self.send("#{flag}=", nil)
end

#skip_versionObject

The skip_version block simply allows for updates to be made to an instance of a versioned ActiveRecord model while ignoring all new version creation. The :if and :unless conditions (if given) will not be evaulated inside a skip_version block.

When the block closes, the instance is automatically saved, so explicitly saving the object within the block is unnecessary.

Example

user = User.find_by_first_name("Steve")
user.version # => 1
user.skip_version do
  user.first_name = "Stephen"
end
user.version # => 1


179
180
181
182
183
# File 'lib/vestal_versions/control.rb', line 179

def skip_version
  _with_version_flag(:_skip_version) do
    yield if block_given?
  end
end