Skip to content

Commit

Permalink
remove abstract class check and restore old behavior of v4.1.1 but ke…
Browse files Browse the repository at this point in the history
…ep the optional no_direct_assignment functiuonality
  • Loading branch information
Denny Mueller authored and Anil Kumar Maurya committed Apr 24, 2019
1 parent 05a0f37 commit d185921
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions lib/aasm/base.rb
Expand Up @@ -54,25 +54,16 @@ def initialize(klass, name, state_machine, options={}, &block)
# make sure to raise an error if no_direct_assignment is enabled
# and attribute is directly assigned though
aasm_name = @name
return true if should_not_define_method(klass) && !@state_machine.config.no_direct_assignment
klass.send :define_method, "#{@state_machine.config.column}=", ->(state_name) do
if self.class.aasm(:"#{aasm_name}").state_machine.config.no_direct_assignment
raise AASM::NoDirectAssignmentError.new(
'direct assignment of AASM column has been disabled (see AASM configuration for this class)'
)
else
super(state_name)

if @state_machine.config.no_direct_assignment
@klass.send(:define_method, "#{@state_machine.config.column}=") do |state_name|
if self.class.aasm(:"#{aasm_name}").state_machine.config.no_direct_assignment
raise AASM::NoDirectAssignmentError.new('direct assignment of AASM column has been disabled (see AASM configuration for this class)')
end
end
end
end

def should_not_define_method(klass)
(klass.methods.include?(:abstract_class) &&
klass.abstract_class) ||
(klass.superclass.methods.include?(:abstract_class) &&
klass.superclass.abstract_class)
end

# This method is both a getter and a setter
def attribute_name(column_name=nil)
if column_name
Expand Down

0 comments on commit d185921

Please sign in to comment.