Module: VestalVersions::Conditions::ClassMethods

Defined in:
lib/vestal_versions/conditions.rb

Overview

Class methods on ActiveRecord::Base to prepare the :if and :unless options.

Instance Method Summary collapse

Instance Method Details

#prepare_versioned_options_with_conditions(options) ⇒ Object

After the original prepare_versioned_options method cleans the given options, this alias also extracts the :if and :unless options, chaning them into arrays and converting any symbols to procs. Procs are called with the ActiveRecord model instance as the sole argument.

If all of the :if conditions are met and none of the :unless conditions are unmet, than version creation will proceed, assuming all other conditions are also met.



28
29
30
31
32
33
34
35
# File 'lib/vestal_versions/conditions.rb', line 28

def prepare_versioned_options_with_conditions(options)
  result = prepare_versioned_options_without_conditions(options)

  self.vestal_versions_options[:if] = Array(options.delete(:if)).map(&:to_proc)
  self.vestal_versions_options[:unless] = Array(options.delete(:unless)).map(&:to_proc)

  result
end