class EnumStateMachine::YARD::Handlers::Transition
Handles and processes transition
Public Instance Methods
process()
click to toggle source
# File lib/enum_state_machine/yard/handlers/transition.rb 8 def process 9 if [EnumStateMachine::Machine, EnumStateMachine::Event, EnumStateMachine::State].include?(owner.class) 10 options = {} 11 12 # Extract requirements 13 ast = statement.parameters.first 14 ast.children.each do |assoc| 15 # Skip conditionals 16 next if %w(if unless).include?(assoc[0].jump(:ident).source) 17 18 options[extract_requirement(assoc[0])] = extract_requirement(assoc[1]) 19 end 20 21 owner.transition(options) 22 end 23 end
Private Instance Methods
extract_requirement(ast)
click to toggle source
Extracts the statement requirement from the given node
# File lib/enum_state_machine/yard/handlers/transition.rb 27 def extract_requirement(ast) 28 case ast.type 29 when :symbol_literal, :string_literal, :array 30 extract_node_names(ast, false) 31 when :binary 32 AllMatcher.instance - extract_node_names(ast.children.last) 33 when :var_ref, :vcall 34 case ast.source 35 when 'nil' 36 nil 37 when 'same' 38 LoopbackMatcher.instance 39 else 40 AllMatcher.instance 41 end 42 end 43 end