Class: Opto::Setter
- Inherits:
-
Object
- Object
- Opto::Setter
- Defined in:
- lib/opto/setter.rb
Overview
Base for Setters.
Resolvers are scripts that can retrieve or generate a value for an option. Such resolvers are for example Env, which can try to find the value for the option from an environment variable. An example of generators is RandomString, which can generate random strings of defined length.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#hint ⇒ Object
Returns the value of attribute hint.
-
#option ⇒ Object
Returns the value of attribute option.
Class Method Summary collapse
-
.for(target) ⇒ Object
Find a setter using a target_name definition, such as :env or :file.
- .inherited(where) ⇒ Object
- .target ⇒ Object
- .targets ⇒ Object
Instance Method Summary collapse
-
#initialize(hint = nil, option = nil) ⇒ Opto::Resolver
constructor
Initialize an instance of a setter.
-
#set(value) ⇒ Object
This is a “base” class, you’re supposed to inherit from this in your setter and define a #set method.
-
#target ⇒ Object
The target “tag” of this resolver, for example: ‘file’ or ‘env’.
Constructor Details
#initialize(hint = nil, option = nil) ⇒ Opto::Resolver
Initialize an instance of a setter.
43 44 45 46 |
# File 'lib/opto/setter.rb', line 43 def initialize(hint = nil, option = nil) @hint = hint @option = option end |
Instance Attribute Details
#hint ⇒ Object
Returns the value of attribute hint.
15 16 17 |
# File 'lib/opto/setter.rb', line 15 def hint @hint end |
#option ⇒ Object
Returns the value of attribute option.
16 17 18 |
# File 'lib/opto/setter.rb', line 16 def option @option end |
Class Method Details
.for(target) ⇒ Object
Find a setter using a target_name definition, such as :env or :file
21 22 23 24 |
# File 'lib/opto/setter.rb', line 21 def for(target) raise NameError, "Unknown setter: #{target}" unless targets[target] targets[target] end |
.inherited(where) ⇒ Object
26 27 28 |
# File 'lib/opto/setter.rb', line 26 def inherited(where) targets[where.target] = where end |
.target ⇒ Object
34 35 36 |
# File 'lib/opto/setter.rb', line 34 def target name.to_s.split('::').last.snakecase.to_sym end |
.targets ⇒ Object
30 31 32 |
# File 'lib/opto/setter.rb', line 30 def targets @targets ||= {} end |
Instance Method Details
#set(value) ⇒ Object
This is a “base” class, you’re supposed to inherit from this in your setter and define a #set method.
49 50 51 |
# File 'lib/opto/setter.rb', line 49 def set(value) raise RuntimeError, "#{self.class}.set not defined" end |
#target ⇒ Object
The target “tag” of this resolver, for example: ‘file’ or ‘env’
54 55 56 |
# File 'lib/opto/setter.rb', line 54 def target self.class.target end |