mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
Adding RubyMotion support.
Changed all string-based eval logic to use RubyMotion supported logic instead.
This commit is contained in:
parent
bdf7e4c97b
commit
a8058bfc91
2 changed files with 28 additions and 30 deletions
|
@ -31,17 +31,16 @@ 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
|
||||||
@klass.class_eval %Q(
|
aasm_name = @name
|
||||||
def #{@state_machine.config.column}=(state_name)
|
@klass.send :define_method, "#{@state_machine.config.column}=", ->(state_name) do
|
||||||
if self.class.aasm(:#{@name}).state_machine.config.no_direct_assignment
|
if self.class.aasm(:"#{aasm_name}").state_machine.config.no_direct_assignment
|
||||||
raise AASM::NoDirectAssignmentError.new(
|
raise AASM::NoDirectAssignmentError.new(
|
||||||
'direct assignment of AASM column has been disabled (see AASM configuration for this class)'
|
'direct assignment of AASM column has been disabled (see AASM configuration for this class)'
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
super
|
super(state_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# This method is both a getter and a setter
|
# This method is both a getter and a setter
|
||||||
|
@ -70,11 +69,10 @@ module AASM
|
||||||
warn "#{@klass.name}: The aasm state name #{name} is already used!"
|
warn "#{@klass.name}: The aasm state name #{name} is already used!"
|
||||||
end
|
end
|
||||||
|
|
||||||
@klass.class_eval <<-EORUBY, __FILE__, __LINE__ + 1
|
aasm_name = @name
|
||||||
def #{name}?
|
@klass.send :define_method, "#{name}?", ->() do
|
||||||
aasm(:#{@name}).current_state == :#{name}
|
aasm(:"#{aasm_name}").current_state == :"#{name}"
|
||||||
end
|
end
|
||||||
EORUBY
|
|
||||||
|
|
||||||
unless @klass.const_defined?("STATE_#{name.upcase}")
|
unless @klass.const_defined?("STATE_#{name.upcase}")
|
||||||
@klass.const_set("STATE_#{name.upcase}", name)
|
@klass.const_set("STATE_#{name.upcase}", name)
|
||||||
|
@ -92,21 +90,21 @@ module AASM
|
||||||
# an addition over standard aasm so that, before firing an event, you can ask
|
# an addition over standard aasm so that, before firing an event, you can ask
|
||||||
# may_event? and get back a boolean that tells you whether the guard method
|
# may_event? and get back a boolean that tells you whether the guard method
|
||||||
# on the transition will let this happen.
|
# on the transition will let this happen.
|
||||||
@klass.class_eval <<-EORUBY, __FILE__, __LINE__ + 1
|
aasm_name = @name
|
||||||
def may_#{name}?(*args)
|
|
||||||
aasm(:#{@name}).may_fire_event?(:#{name}, *args)
|
@klass.send :define_method, "may_#{name}?", ->(*args) do
|
||||||
|
aasm(:"#{aasm_name}").may_fire_event?(:"#{name}", *args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def #{name}!(*args, &block)
|
@klass.send :define_method, "#{name}!", ->(*args, &block) do
|
||||||
aasm(:#{@name}).current_event = :#{name}!
|
aasm(:"#{aasm_name}").current_event = :"#{name}!"
|
||||||
aasm_fire_event(:#{@name}, :#{name}, {:persist => true}, *args, &block)
|
aasm_fire_event(:"#{aasm_name}", :"#{name}", {:persist => true}, *args, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def #{name}(*args, &block)
|
@klass.send :define_method, "#{name}", ->(*args, &block) do
|
||||||
aasm(:#{@name}).current_event = :#{name}
|
aasm(:"#{aasm_name}").current_event = :"#{name}"
|
||||||
aasm_fire_event(:#{@name}, :#{name}, {:persist => false}, *args, &block)
|
aasm_fire_event(:"#{aasm_name}", :"#{name}", {:persist => false}, *args, &block)
|
||||||
end
|
end
|
||||||
EORUBY
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_all_transitions(*callbacks, &block)
|
def after_all_transitions(*callbacks, &block)
|
||||||
|
|
|
@ -23,7 +23,7 @@ module AASM
|
||||||
|
|
||||||
def include_persistence(base, type)
|
def include_persistence(base, type)
|
||||||
require File.join(File.dirname(__FILE__), 'persistence', "#{type}_persistence")
|
require File.join(File.dirname(__FILE__), 'persistence', "#{type}_persistence")
|
||||||
base.send(:include, constantize("AASM::Persistence::#{capitalize(type)}Persistence"))
|
base.send(:include, constantize("#{capitalize(type)}Persistence"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def capitalize(string_or_symbol)
|
def capitalize(string_or_symbol)
|
||||||
|
@ -31,7 +31,7 @@ module AASM
|
||||||
end
|
end
|
||||||
|
|
||||||
def constantize(string)
|
def constantize(string)
|
||||||
instance_eval(string)
|
AASM::Persistence.const_get(string)
|
||||||
end
|
end
|
||||||
|
|
||||||
end # class << self
|
end # class << self
|
||||||
|
|
Loading…
Reference in a new issue