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

Do not define column setter for absctract class

This commit is contained in:
Anil Maurya 2019-04-21 13:04:52 +05:30 committed by Anil Kumar Maurya
parent 4427c353a3
commit 23f98a100d

View file

@ -54,13 +54,16 @@ module AASM
# make sure to raise an error if no_direct_assignment is enabled
# and attribute is directly assigned though
aasm_name = @name
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 !(klass.superclass.methods.include?(:abstract_class) &&
klass.superclass.abstract_class)
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)
end
end
end
end