Method: Danger::PluginParser#method_parser

Defined in:
lib/danger/plugin_support/plugin_parser.rb

#method_parser(gem_path, meth) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/danger/plugin_support/plugin_parser.rb', line 126

def method_parser(gem_path, meth)
  return nil if meth.nil?
  method = {
    name: meth.name,
    body_md: meth.docstring,
    params: meth.parameters,
    files: meth.files.map { |item| [item.first.gsub(gem_path, ""), item.last] },
    tags: meth.tags.map { |t| { name: t.tag_name, types: t.types } }
  }


  return_v = method_return_string(method)
  params_v = method_params(method)

  # Pull out some derived data
  method[:param_couplets] = params_v
  method[:return] = return_v

  # Create the center params, `thing: OK, other: Thing`
  string_params = params_v.map do |param|
    name = param.keys.first
    param[name].nil? ? name : name + ": " + param[name]
  end.join ", "

  # Wrap it in () if there _are_ params
  string_params = "(" + string_params + ")" unless string_params.empty?
  # Append the return type if we have one
  suffix = return_v.empty? ? "" : " -> #{return_v}"

  method[:one_liner] = meth.name.to_s + string_params + suffix
  method
end