class Opto::Setter
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.
Attributes
Public Class Methods
Find a setter using a target_name definition, such as :env or :file @param [Symbol, String] target
# File lib/opto/setter.rb, line 21 def for(target) raise NameError, "Unknown setter: #{target}" unless targets[target] targets[target] end
# File lib/opto/setter.rb, line 26 def inherited(where) targets[where.target] = where end
Initialize an instance of a setter. @param hint A “hint” for the setter, for example. the environment variable name @param [Opto::Option] option The option parent of this resolver instance @return [Opto::Resolver]
# File lib/opto/setter.rb, line 43 def initialize(hint = nil, option = nil) @hint = hint @option = option end
# File lib/opto/setter.rb, line 34 def target name.to_s.split('::').last.snakecase.to_sym end
# File lib/opto/setter.rb, line 30 def targets @targets ||= {} end
Public Instance Methods
This is a “base” class, you're supposed to inherit from this in your setter and define a set
method.
# File lib/opto/setter.rb, line 49 def set(value) raise RuntimeError, "#{self.class}.set not defined" end
The target “tag” of this resolver, for example: 'file' or 'env'
# File lib/opto/setter.rb, line 54 def target self.class.target end