mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
remove abstract class check and restore old behavior of v4.1.1 but keep the optional no_direct_assignment functiuonality
This commit is contained in:
parent
05a0f37e0f
commit
d185921d90
1 changed files with 6 additions and 15 deletions
|
@ -54,23 +54,14 @@ module AASM
|
|||
# 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)
|
||||
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)
|
||||
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
|
||||
|
||||
# This method is both a getter and a setter
|
||||
|
|
Loading…
Reference in a new issue