lib/machine.rb in state-fu-0.13.4 vs lib/machine.rb in state-fu-0.13.5
- old
+ new
@@ -32,13 +32,14 @@
def self.bind!(machine, owner, name, options={})
name = name.to_sym
options[:define_methods] = (name == DEFAULT) unless options.symbolize_keys!.has_key?(:define_methods)
options[:field_name] ||= Persistence.default_field_name(name)
options[:singleton] = true unless owner.is_a?(Class)
- # define an accessor method with the given name
if options[:singleton]
_binding = StateFu::Binding.new machine, owner, name, options
+
+ # define an accessor method with the given name
MethodFactory.define_singleton_method(owner, name) { _binding }
if alias_name = options[:alias] || options[:as]
MethodFactory.define_singleton_method(owner, alias_name) { _binding }
end
else
@@ -189,7 +190,20 @@
def graphviz
@graphviz ||= Plotter.new(self).output
end
+ def to_yaml
+ StateFu::Blueprint.to_yaml(self)
+ end
+
+ # TODO simplify this by adding serializable? to state & event
+ def serializable?
+ named_procs.empty? && (states + events).all?(&:serializable?)
+ end
+
+ def self.load_yaml(yaml)
+ StateFu::Blueprint.load_yaml(yaml)
+ end
+
end
end