Gathers method attributes by redefining method_added and capturing method calls before a method. This module also saves method locations so CommentInspector can scrape their commented method attributes.
Constants
METHODS | = | [:config, :desc, :options, :render_options] |
CALLER_REGEXP | = | RUBY_VERSION < '1.9' ? /in `load_source'/ : /in `<module:.*>'/ |
Attributes
current_module | [RW] | |
mod_store | [R] |
Public instance methods
find_method_locations
(stack)
Returns an array of the file and line number at which a method starts using a caller array. Necessary information for CommentInspector to function.
[show source]
# File lib/boson/inspectors/method_inspector.rb, line 53 def find_method_locations(stack) if (line = stack.find {|e| e =~ CALLER_REGEXP }) (line =~ /^(.*):(\d+)/) ? [$1, $2.to_i] : nil end end
new_method_added
(mod, meth)
The method_added used while scraping method attributes.
[show source]
# File lib/boson/inspectors/method_inspector.rb, line 13 def new_method_added(mod, meth) return unless mod.name[/^Boson::Commands::/] self.current_module = mod store[:temp] ||= {} METHODS.each do |e| store[e][meth.to_s] = store[:temp][e] if store[:temp][e] end if store[:temp].size < METHODS.size store[:method_locations] ||= {} if (result = find_method_locations(caller)) store[:method_locations][meth.to_s] = result end end store[:temp] = {} scrape_arguments(meth) if has_inspector_method?(meth, :options) || has_inspector_method?(meth,:render_options) end
scrape_arguments
(meth)
Scrapes a method’s arguments using ArgumentInspector.
[show source]
# File lib/boson/inspectors/method_inspector.rb, line 39 def scrape_arguments(meth) store[:args] ||= {} o = Object.new o.extend(@current_module) # private methods return nil if (val = ArgumentInspector.scrape_with_eval(meth, @current_module, o)) store[:args][meth.to_s] = val end end