Module: YardThunder::MethodHandlerOptionMixin

Included in:
YARD::Handlers::Ruby::MethodHandler
Defined in:
lib/yard-thunder/options.rb

Overview

process do

  parser.extra_state ||= {}
  parser.extra_state[:thunder_options] ||= []
  parser.extra_state[:thunder_options] << tokval_list(statement.tokens[1..-1], :attr)
end

end

Instance Method Summary collapse

Instance Method Details

#processObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/yard-thunder/options.rb', line 30

def process
  super
  return unless parser.extra_state
  # handle any options for this command
  if parser.extra_state.thunder_options
    # add the options parameter to the method if it's not already there
    unless @registered_object.tags(:param).find {|x| x.name == "options"}
      option_param = YARD::Tags::Tag.new(:param, "a customizable set of options", "Hash", "options")
      @registered_object.docstring.add_tag(option_param)
    end

    # trick the parser to parse the option as a YARDoc tag
    parser.extra_state.thunder_options.each do |option|
      name = option[:name]
      description = option[:desc] || ""
      if option[:default]
        unless description.lstrip.start_with? /\(.+\)/
          description = "(#{option[:default]}) #{description}"
        end
      end
      type = option[:type] || "String"

      text = "options #{name} [#{type}] #{description}"
      option_tag = YARD::Tags::Library.default_factory.parse_tag_with_options(:option, text)
      @registered_object.docstring.add_tag(option_tag)
    end
    parser.extra_state.thunder_options = nil
  end
end