Skip to content

Commit

Permalink
Refactor change
Browse files Browse the repository at this point in the history
  • Loading branch information
mclement18 committed Sep 23, 2021
1 parent 4a450b0 commit 61fe78e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/aasm/base.rb
Expand Up @@ -55,7 +55,7 @@ def initialize(klass, name, state_machine, options={}, &block)
configure :logger, Logger.new(STDERR)

# setup timestamp-setting callback if enabled
setup_timestamps(@name, namespace)
setup_timestamps(@name)

# make sure to raise an error if no_direct_assignment is enabled
# and attribute is directly assigned though
Expand Down Expand Up @@ -263,11 +263,12 @@ def skip_instance_level_validation(event, name, aasm_name, klass)
end
end

def setup_timestamps(aasm_name, namespace)
def setup_timestamps(aasm_name)
return unless @state_machine.config.timestamps

after_all_transitions do
if self.class.aasm(:"#{aasm_name}").state_machine.config.timestamps
namespace = self.class.aasm(:"#{aasm_name}").state_machine.config.namespace
base_setter = "#{aasm(aasm_name).to_state}_at="
ts_setter = !!namespace ? "#{namespace}_#{base_setter}" : base_setter
respond_to?(ts_setter) && send(ts_setter, ::Time.now)
Expand Down

0 comments on commit 61fe78e

Please sign in to comment.