1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00

provide a configuration class (to easily spot configuration options)

This commit is contained in:
Thorsten Böttger 2014-07-13 14:07:37 +02:00
parent 3bbbd64fd9
commit 55f1eed4fa
4 changed files with 23 additions and 2 deletions

View file

@ -3,6 +3,7 @@ require 'ostruct'
%w( %w(
version version
errors errors
configuration
base base
instance_base instance_base
transition transition

View file

@ -95,7 +95,6 @@ module AASM
private private
def configure(key, default_value) def configure(key, default_value)
@state_machine.config.send(:new_ostruct_member, key)
if @options.key?(key) if @options.key?(key)
@state_machine.config.send("#{key}=", @options[key]) @state_machine.config.send("#{key}=", @options[key])
elsif @state_machine.config.send(key).nil? elsif @state_machine.config.send(key).nil?

21
lib/aasm/configuration.rb Normal file
View file

@ -0,0 +1,21 @@
module AASM
class Configuration
# for all persistence layers: which database column to use?
attr_accessor :column
# let's cry if the transition is invalid
attr_accessor :whiny_transitions
# for all persistence layers: create named scopes for each state
attr_accessor :create_scopes
# for ActiveRecord: don't store any new state if the model is invalid
attr_accessor :skip_validation_on_save
# for ActiveRecord: use requires_new for nested transactions?
attr_accessor :requires_new_transaction
# forbid direct assignment in aasm_state column (in ActiveRecord)
attr_accessor :no_direct_assignment
end
end

View file

@ -19,7 +19,7 @@ module AASM
@initial_state = nil @initial_state = nil
@states = [] @states = []
@events = {} @events = {}
@config = OpenStruct.new @config = AASM::Configuration.new
end end
# called internally by Ruby 1.9 after clone() # called internally by Ruby 1.9 after clone()