Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Register state event attributes in YARD integration

  • Loading branch information...
commit dab435f69ebc835fdb8d0b4ae76c92c796ee3856 1 parent 3b60d73
@obrie obrie authored
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 = [
Please sign in to comment.
Something went wrong with that request. Please try again.