Sha256: cd748d1e98c60e1868fedde89d845947434e8c5d4d249b35044dc6825a255bcd
Contents?: true
Size: 1.53 KB
Versions: 13
Compression:
Stored size: 1.53 KB
Contents
require_relative 'forwarding/rule' require_relative 'forwarding/proxy' class EcoRake module Options # Offers a way to relaunch command options from options results. module Forwarding class << self def included(base) super(base) base.extend ClassMethods base.attr_inheritable(:options_proxy) {|value, subclass| value&.deep_dup(subclass)} end end module ClassMethods # Service class to forward options. def options_proxy @options_proxy ||= EcoRake::Options::Forwarding::Proxy.new(self) end # Declare the forwarding rules for options. # @param rules [Hash] where keys are option names or shorts and values the rules. def option_forwarding(**rules) rules.each do |sym, rule| options_proxy.add(sym, rule, override: true) end end end # @param sym [Symbol] a short or name of an option that may be present in `from` # @param from [Hash] the parsed option results. # @return [Value] the value defined by the `rule` linked to `opt` def forward_option(sym, from: options) self.class.options_proxy.forward(sym, from: from) end # @see `#forward_option` (the same but for multiple options) # @return [Array<Value>] the values defined by the `rules` linked to `opts` def forward_options(*syms, from: options) syms.map {|sym| forward_option(sym, from: from)} end end end end
Version data entries
13 entries across 13 versions & 1 rubygems