Skip to content

Commit

Permalink
Remove Deadcode
Browse files Browse the repository at this point in the history
  • Loading branch information
seuros committed Apr 18, 2021
1 parent cbefdc2 commit 7a11953
Showing 1 changed file with 10 additions and 59 deletions.
69 changes: 10 additions & 59 deletions lib/state_machines/integrations/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -435,72 +435,23 @@ def runs_validations_on_action?
end

# Gets the db default for the machine's attribute
if ::ActiveRecord.gem_version >= Gem::Version.new('4.2.0')
def owner_class_attribute_default
if owner_class.connected? && owner_class.table_exists?
owner_class.column_defaults[attribute.to_s]
end
end
else
def owner_class_attribute_default
if owner_class.connected? && owner_class.table_exists?
if column = owner_class.columns_hash[attribute.to_s]
column.default
end
end
def owner_class_attribute_default
if owner_class.connected? && owner_class.table_exists?
owner_class.column_defaults[attribute.to_s]
end
end

def define_state_initializer
if ::ActiveRecord.gem_version >= Gem::Version.new('5.0.0.alpha')
define_helper :instance, <<-end_eval, __FILE__, __LINE__ + 1
def initialize(attributes = nil, *)
super(attributes) do |*args|
scoped_attributes = (attributes || {}).merge(self.class.scope_attributes)
self.class.state_machines.initialize_states(self, {}, scoped_attributes)
yield(*args) if block_given?
end
end
end_eval
elsif ::ActiveRecord.gem_version >= Gem::Version.new('4.2')
define_helper :instance, <<-end_eval, __FILE__, __LINE__ + 1
def initialize(attributes = nil, options = {})
scoped_attributes = (attributes || {}).merge(self.class.scope_attributes)
super(attributes, options) do |*args|
self.class.state_machines.initialize_states(self, {}, scoped_attributes)
yield(*args) if block_given?
end
end
end_eval
else
# Initializes static states
#
# This is the only available hook where the default set of attributes
# can be overridden for a new object *prior* to the processing of the
# attributes passed into #initialize
define_helper :class, <<-end_eval, __FILE__, __LINE__ + 1
def column_defaults(*) #:nodoc:
result = super
# No need to pass in an object, since the overrides will be forced
self.state_machines.initialize_states(nil, :static => :force, :dynamic => false, :to => result)
result
end
end_eval

# Initializes dynamic states
define_helper :instance, <<-end_eval, __FILE__, __LINE__ + 1
def initialize(attributes = nil, options = {})
define_helper :instance, <<-end_eval, __FILE__, __LINE__ + 1
def initialize(attributes = nil, *)
super(attributes) do |*args|
scoped_attributes = (attributes || {}).merge(self.class.scope_attributes)
super(attributes, options) do |*args|
self.class.state_machines.initialize_states(self, {}, scoped_attributes)
yield(*args) if block_given?
end
self.class.state_machines.initialize_states(self, {}, scoped_attributes)
yield(*args) if block_given?
end
end_eval
end
end
end_eval
end

# Uses around callbacks to run state events if using the :save hook
Expand Down

0 comments on commit 7a11953

Please sign in to comment.