Module: Trains::Utils::Args
- Included in:
- Visitor::Controller, Visitor::Migration, Visitor::Route
- Defined in:
- lib/trains/utils/args.rb
Overview
utility module to deal with parsing of arguments
Instance Method Summary collapse
Instance Method Details
#parse_args(node) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/trains/utils/args.rb', line 7 def parse_args(node) return if node.nil? case node.type when :hash parse_hash(node) else parse_value(node) end end |
#parse_hash(node) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/trains/utils/args.rb', line 18 def parse_hash(node) = {} return unless node.type == :hash node.each_pair { |key, value| [key.value] = parse_value(value) } rescue StandardError => e puts 'Error boi' puts e puts node.parent ensure return end |
#parse_value(node) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/trains/utils/args.rb', line 31 def parse_value(node) case node.type when :hash parse_hash(node) when :array node.values.map { |value| parse_value(value) } when :send if node.method_name == :redirect { redirect: node.arguments.first.value } end # skipcq: RB-LI1006 when :true true # skipcq: RB-LI1006 when :false false when :sym, :str, :integer node.value end end |