Class: Jazzy::Config::Attribute
- Inherits:
-
Object
- Object
- Jazzy::Config::Attribute
- Defined in:
- lib/jazzy/config.rb
Overview
rubocop:disable Style/AccessorMethodName
Instance Attribute Summary collapse
-
#command_line ⇒ Object
readonly
Returns the value of attribute command_line.
-
#config_file_key ⇒ Object
readonly
Returns the value of attribute config_file_key.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parse ⇒ Object
readonly
Returns the value of attribute parse.
Instance Method Summary collapse
- #attach_to_option_parser(config, opt) ⇒ Object
- #configured?(config) ⇒ Boolean
- #get(config) ⇒ Object
-
#initialize(name, description: nil, command_line: nil, default: nil, parse: ->(x) { x }) ⇒ Attribute
constructor
A new instance of Attribute.
- #set(config, val, mark_configured: true) ⇒ Object
- #set_if_unconfigured(config, val) ⇒ Object
- #set_raw(config, val) ⇒ Object
- #set_to_default(config) ⇒ Object
Constructor Details
#initialize(name, description: nil, command_line: nil, default: nil, parse: ->(x) { x }) ⇒ Attribute
Returns a new instance of Attribute.
16 17 18 19 20 21 22 23 24 |
# File 'lib/jazzy/config.rb', line 16 def initialize(name, description: nil, command_line: nil, default: nil, parse: ->(x) { x }) @name = name.to_s @description = Array(description) @command_line = Array(command_line) @default = default @parse = parse @config_file_key = full_command_line_name || @name end |
Instance Attribute Details
#command_line ⇒ Object (readonly)
Returns the value of attribute command_line.
13 14 15 |
# File 'lib/jazzy/config.rb', line 13 def command_line @command_line end |
#config_file_key ⇒ Object (readonly)
Returns the value of attribute config_file_key.
13 14 15 |
# File 'lib/jazzy/config.rb', line 13 def config_file_key @config_file_key end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
13 14 15 |
# File 'lib/jazzy/config.rb', line 13 def default @default end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
13 14 15 |
# File 'lib/jazzy/config.rb', line 13 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/jazzy/config.rb', line 13 def name @name end |
#parse ⇒ Object (readonly)
Returns the value of attribute parse.
13 14 15 |
# File 'lib/jazzy/config.rb', line 13 def parse @parse end |
Instance Method Details
#attach_to_option_parser(config, opt) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/jazzy/config.rb', line 51 def attach_to_option_parser(config, opt) return if command_line.empty? opt.on(*command_line, *description) do |val| set(config, val) end end |
#configured?(config) ⇒ Boolean
47 48 49 |
# File 'lib/jazzy/config.rb', line 47 def configured?(config) config.method("#{name}_configured").call end |
#get(config) ⇒ Object
26 27 28 |
# File 'lib/jazzy/config.rb', line 26 def get(config) config.method(name).call end |
#set(config, val, mark_configured: true) ⇒ Object
34 35 36 37 |
# File 'lib/jazzy/config.rb', line 34 def set(config, val, mark_configured: true) set_raw(config, config.instance_exec(val, &parse)) config.method("#{name}_configured=").call(true) if mark_configured end |
#set_if_unconfigured(config, val) ⇒ Object
43 44 45 |
# File 'lib/jazzy/config.rb', line 43 def set_if_unconfigured(config, val) set(config, val) unless configured?(config) end |
#set_raw(config, val) ⇒ Object
30 31 32 |
# File 'lib/jazzy/config.rb', line 30 def set_raw(config, val) config.method("#{name}=").call(val) end |
#set_to_default(config) ⇒ Object
39 40 41 |
# File 'lib/jazzy/config.rb', line 39 def set_to_default(config) set(config, default, mark_configured: false) if default end |