Class: EcoRake::Options::Forwarding::Proxy
- Inherits:
-
Object
- Object
- EcoRake::Options::Forwarding::Proxy
- Includes:
- Enumerable
- Defined in:
- lib/eco-rake/options/forwarding/proxy.rb
Overview
Note:
rules keep associated with the option name
(not their short
)
- The above means that changing the name of an exisint option will brake the link with a forwarding rule (as they do not auto-update on option name change)
Collection of forwarding rules.
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #[](value) ⇒ EcoRake::Options::Forwarding::Rule
-
#add(sym, rule, override: true, require_option: true) ⇒ Object
Adds a new rule or overrides an existing one.
-
#delete(ref) ⇒ EcoRake::Options::Forwarding::Rule
The rule that has been deleted.
-
#dup(parent, override: true, require_option: false) ⇒ EcoRake::Options::Forwarding::Proxy
(also: #deep_dup)
With a copy of the rules.
- #each(&block) ⇒ Object
-
#forward(sym, from:) ⇒ Value
It applies the rule associated with
sym
tofrom
parsed option results. -
#initialize(parent) ⇒ Proxy
constructor
A new instance of Proxy.
Constructor Details
#initialize(parent) ⇒ Proxy
Returns a new instance of Proxy.
14 15 16 17 18 19 20 |
# File 'lib/eco-rake/options/forwarding/proxy.rb', line 14 def initialize(parent) pklass = parent.is_a?(Class)? parent : parent.class msg = "Expecting parent to be RakeCommander::Options::Class. Given: #{pklass}" raise ArgumentError, msg unless parent.is_a?(Class) && parent <= RakeCommander::Options @parent = parent @rules = {} end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
11 12 13 |
# File 'lib/eco-rake/options/forwarding/proxy.rb', line 11 def parent @parent end |
Instance Method Details
#[](value) ⇒ EcoRake::Options::Forwarding::Rule
36 37 38 |
# File 'lib/eco-rake/options/forwarding/proxy.rb', line 36 def [](value) @rules[key(value)] end |
#add(sym, rule, override: true, require_option: true) ⇒ Object
Adds a new rule or overrides an existing one.
42 43 44 45 46 47 48 |
# File 'lib/eco-rake/options/forwarding/proxy.rb', line 42 def add(sym, rule, override: true, require_option: true) add_rule( EcoRake::Options::Forwarding::Rule.new(key(sym) || sym, rule, parent: self), override: override, require_option: require_option ) end |
#delete(ref) ⇒ EcoRake::Options::Forwarding::Rule
Returns the rule that has been deleted.
52 53 54 |
# File 'lib/eco-rake/options/forwarding/proxy.rb', line 52 def delete(ref) @rules.delete(key(ref)) end |
#dup(parent, override: true, require_option: false) ⇒ EcoRake::Options::Forwarding::Proxy Also known as: deep_dup
Returns with a copy of the rules.
28 29 30 31 32 |
# File 'lib/eco-rake/options/forwarding/proxy.rb', line 28 def dup(parent, override: true, require_option: false) self.class.new(parent).tap do |rely| each {|rule| rely.add_rule(rule.deep_dup, override: override, require_option: require_option)} end end |
#each(&block) ⇒ Object
22 23 24 25 |
# File 'lib/eco-rake/options/forwarding/proxy.rb', line 22 def each(&block) return to_enum(:each) unless block_given? @rules.values.each(&block) end |
#forward(sym, from:) ⇒ Value
It applies the rule associated with sym
to from
parsed option results.
60 61 62 |
# File 'lib/eco-rake/options/forwarding/proxy.rb', line 60 def forward(sym, from:) self[sym]&.apply(from) end |