Skip to content

Commit

Permalink
Merge pull request #42 from casperisfine/eliminate-open-struct
Browse files Browse the repository at this point in the history
feat: Eliminate usage of OpenStruct
  • Loading branch information
seuros authored Jan 22, 2024
2 parents 6fecaa1 + 7cac29f commit 4277c8b
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions lib/state_machines/audit_trail/transition_auditing.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'ostruct'
#
# This module inserts hooks into the state machine.
# The transition_class is the class (optionally specified with the :class option) for the model which
Expand All @@ -7,6 +6,30 @@
# Multiple `SubscriptionStateTransition`s compose the 'audit_trail'.
#
module StateMachines::AuditTrail::TransitionAuditing
class InitialTransition
attr_reader :namespace, :to

def initialize(namespace:, to:)
@namespace = namespace
@to = to
end

def from
nil
end

def event
nil
end

def machine
nil
end

def args
nil
end
end

# Hook for audit_trail inside a a state_machine declaration.
#
Expand Down Expand Up @@ -35,7 +58,7 @@ def audit_trail(options = {})
if state_machine.backend.new_record? object
current_state = object.send(state_machine.attribute)
if !current_state.nil?
state_machine.backend.log(object, OpenStruct.new(namespace: state_machine.namespace, to: current_state))
state_machine.backend.log(object, InitialTransition.new(namespace: state_machine.namespace, to: current_state))
end
end
end
Expand Down

0 comments on commit 4277c8b

Please sign in to comment.