Class: YARD::Amp::LegacyCommandHandler

Inherits:
Handlers::Ruby::Legacy::Base
  • Object
show all
Includes:
ParsingHelpers
Defined in:
lib/yard-amp/legacy_handler.rb

Overview

This handler is used by the Ruby 1.9+ parser engine. Uses AST nodes.

All the interesting logic is actually all in SharedMethods. This class specifically defines the parsing logic to get the data ready for the Shared Methods.

Constant Summary collapse

MATCH =
/command\(?\s*(.*?)\s*\)?\s*(do|\{)/

Instance Method Summary collapse

Methods included from ParsingHelpers

#clean_string, #construct_docstring, #parse_hash, #split_by_comma_smart

Instance Method Details

#commands_moduleObject



35
36
37
38
# File 'lib/yard-amp/legacy_handler.rb', line 35

def commands_module
  mod = register ModuleObject.new(:root, "Amp")
  com_mod = register ModuleObject.new(mod, "Commands")
end

#processObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/yard-amp/legacy_handler.rb', line 14

def process
  params = statement.tokens.to_s[MATCH, 1].split(",").map {|x| clean_string(x)}
  if params.size != 1
    raise YARD::Parser::UndocumentableError, 'command declaration with invalid parameters'
  end
  
  command_name = params.first
  command_name = command_name[1..-1] if command_name[0,1] == ":"
  # 
  klass = ClassObject.new(commands_module, command_name.capitalize) do |o|
    o.superclass = P("Amp::Command")
    o.superclass.type = :class if o.superclass.is_a?(Proxy)
  end
  klass[:amp_data] ||= {}
  klass[:amp_data].merge!(:docstring => statement.comments)
  # 
  parse_block(:owner => klass)
  register klass
  construct_docstring(klass)
end