Module: YARD::Handlers::Ruby::DecoratorHandlerMethods
- Included in:
- ModuleFunctionHandler, PrivateClassMethodHandler, PublicClassMethodHandler, VisibilityHandler
- Defined in:
- lib/yard/handlers/ruby/decorator_handler_methods.rb
Overview
Helper methods to assist with processing decorators.
Instance Method Summary collapse
-
#process_decorator(*nodes, opts = {}) {|method, node, name| ... } ⇒ Array<Hash>
Takes care of parsing method definitions passed to decorators as parameters, as well as parsing chained decorators.
Instance Method Details
#process_decorator(*nodes, opts = {}) {|method, node, name| ... } ⇒ Array<Hash>
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# 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 |