Permalink
Browse files

Register state event attributes in YARD integration

  • Loading branch information...
1 parent 3b60d73 commit dab435f69ebc835fdb8d0b4ae76c92c796ee3856 @obrie obrie committed Feb 17, 2012
Showing with 23 additions and 1 deletion.
  1. +23 −1 lib/state_machine/yard/handlers/machine.rb
View
24 lib/state_machine/yard/handlers/machine.rb
@@ -69,7 +69,7 @@ def options
ast.children.each do |assoc|
# Only extract important options
key = extract_node_name(assoc[0])
- next unless [:initial, :attribute, :namespace].include?(key)
+ next unless [:initial, :attribute, :namespace, :action].include?(key)
value = extract_node_name(assoc[1])
options[key] = value
@@ -179,6 +179,28 @@ def define_macro_methods
m.parameters = ["new_#{attribute}"]
end
+ if machine.action || integration && integration.defaults[:action]
+ attribute = "#{machine.name}_event"
+ namespace.attributes[:instance][attribute] = {}
+
+ # Machine event attribute getter
+ register(m = ::YARD::CodeObjects::MethodObject.new(namespace, attribute))
+ namespace.attributes[:instance][attribute][:read] = m
+ m.docstring = [
+ "Gets the current event attribute value for the machine",
+ "@return The event attribute value"
+ ]
+
+ # Machine event attribute setter
+ register(m = ::YARD::CodeObjects::MethodObject.new(namespace, "#{attribute}="))
+ namespace.attributes[:instance][attribute][:write] = m
+ m.docstring = [
+ "Sets the current value for the machine",
+ "@param new_#{attribute} The new value to set"
+ ]
+ m.parameters = ["new_#{attribute}"]
+ end
+
# Presence query
register(m = ::YARD::CodeObjects::MethodObject.new(namespace, "#{machine.name}?"))
m.docstring = [

0 comments on commit dab435f

Please sign in to comment.