Module: YARD::Handlers::Ruby::DecoratorHandlerMethods
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/yard/handlers/ruby/decorator_handler_methods.rb |
Overview
Helper methods to assist with processing decorators.
Instance Method Summary
Instance Method Details
#process_decorator(*nodes, opts = {}) {|method, node, name| ... } ⇒ Array<Hash>
# File 'lib/yard/handlers/ruby/decorator_handler_methods.rb', line 43
def process_decorator(*nodes, &block) opts = nodes.last.is_a?(Hash) ? nodes.pop : {} all_nodes = statement.parameters.select do |p| p.is_a? YARD::Parser::Ruby::AstNode end # Parse decorator parameters (decorator chain). all_nodes.each do |param| parse_block param if param.call? || param.def? end selected_nodes = if nodes.empty? all_nodes elsif nodes.count == 1 && nodes.first.nil? [] else nodes end decorated_methods = selected_nodes.map do |param| process_decorator_parameter param, opts, &block end.flatten # Store method nodes in decorator node. statement.define_singleton_method :decorators do decorated_methods.map {|h| h[:node] } end decorated_methods end
#process_decorator_parameter(node, opts = {}) {|method, node, name.to_sym| ... } (private)
# File 'lib/yard/handlers/ruby/decorator_handler_methods.rb', line 78
def process_decorator_parameter(node, opts = {}, &block) scope = opts.fetch :scope, :instance transfer_docstring = opts.fetch :transfer_docstring, true transfer_source = opts.fetch :transfer_source, true name = nil if node.call? if node.respond_to? :decorators return node.decorators.map do |n| process_decorator_parameter n, opts, &block end end elsif node.def? name = node.jump(:def).method_name.source else name = node.jump(:ident, :string_content, :const).source end if name.nil? raise YARD::Parser::UndocumentableError, 'statement, cannot determine method name' end method = YARD::CodeObjects::Proxy.new( namespace, (scope == :instance ? '#' : '.') + name.to_s, :method ) # Transfer source to methods passed to the helper as parameters. method.source = statement.source if transfer_source && node.def? # Transfer decorator docstring to methods passed to the helper as parameters. if transfer_docstring && node.def? && statement.docstring && method.docstring.empty? = method. if method.respond_to? : ||= [] method.docstring = statement.docstring .each {|t| method.add_tag t } end yield method, node, name.to_sym if block_given? [{:method => method, :node => node, :name => name.to_sym}] end