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
|
# make sure to raise an error if no_direct_assignment is enabled
|
||||||
# and attribute is directly assigned though
|
# and attribute is directly assigned though
|
||||||
aasm_name = @name
|
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)
|
if @state_machine.config.no_direct_assignment
|
||||||
(klass.methods.include?(:abstract_class) &&
|
@klass.send(:define_method, "#{@state_machine.config.column}=") do |state_name|
|
||||||
klass.abstract_class) ||
|
if self.class.aasm(:"#{aasm_name}").state_machine.config.no_direct_assignment
|
||||||
(klass.superclass.methods.include?(:abstract_class) &&
|
raise AASM::NoDirectAssignmentError.new('direct assignment of AASM column has been disabled (see AASM configuration for this class)')
|
||||||
klass.superclass.abstract_class)
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# This method is both a getter and a setter
|
# This method is both a getter and a setter
|
||||||
|
|
Loading…
Add table
Reference in a new issue