lib/aasm/base.rb in aasm-4.10.1 vs lib/aasm/base.rb in aasm-4.11.0
- old
+ new
@@ -1,5 +1,7 @@
+require 'logger'
+
module AASM
class Base
attr_reader :klass, :state_machine
@@ -19,10 +21,13 @@
configure :create_scopes, true
# don't store any new state if the model is invalid (in ActiveRecord)
configure :skip_validation_on_save, false
+ # raise if the model is invalid (in ActiveRecord)
+ configure :whiny_persistence, false
+
# use requires_new for nested transactions (in ActiveRecord)
configure :requires_new_transaction, true
# use pessimistic locking (in ActiveRecord)
# true for FOR UPDATE lock
@@ -38,10 +43,13 @@
configure :enum, nil
# Set to true to namespace reader methods and constants
configure :namespace, false
+ # Configure a logger, with default being a Logger to STDERR
+ configure :logger, Logger.new(STDERR)
+
# make sure to raise an error if no_direct_assignment is enabled
# and attribute is directly assigned though
aasm_name = @name
klass.send :define_method, "#{@state_machine.config.column}=", ->(state_name) do
if self.class.aasm(:"#{aasm_name}").state_machine.config.no_direct_assignment
@@ -198,10 +206,10 @@
! ( @state_machine.config.enum &&
klass.respond_to?(:defined_enums) &&
klass.defined_enums.values.any?{ |methods|
methods.keys{| enum | enum + '?' == method_name }
})
- warn "#{klass.name}: overriding method '#{method_name}'!"
+ @state_machine.config.logger.warn "#{klass.name}: overriding method '#{method_name}'!"
end
klass.send(:define_method, method_name, method_definition)
end