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

- (Object) prepare_versioned_options(options)

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.



16
17
18
19
20
21
22
23
# File 'lib/vestal_versions/conditions.rb', line 16

def prepare_versioned_options(options)
  result = super(options)

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

  result
end