Class: LitCLI::Config
- Inherits:
-
Object
- Object
- LitCLI::Config
- Defined in:
- lib/config.rb
Overview
Default config that can be overridden from the command line or application.
@usage:
LitCLI.configure do |config|
config.<property> = <value>
end
@precedence:
3. Defaults - initialize()
2. Application - LitCLI.configure()
1. Command line flags - cli_configure()
Constant Summary collapse
- @@errors =
Track errors and only show them once.
Set.new
Instance Attribute Summary collapse
-
#delay ⇒ Object
Returns the value of attribute delay.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#step ⇒ Object
Returns the value of attribute step.
-
#type ⇒ Object
Returns the value of attribute type.
-
#types ⇒ Object
Returns the value of attribute types.
Instance Method Summary collapse
-
#cli_configure ⇒ Object
Override config from command line.
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #valid?(flags, flag) ⇒ Boolean
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/config.rb', line 30 def initialize() @types = { :info => { icon: "ℹ", color: :blue }, :pass => { icon: "✔", color: :green }, :warn => { icon: "⚠", color: :yellow }, :fail => { icon: "⨯", color: :red }, :error => { icon: "!", color: :red }, :debug => { icon: "?", color: :purple }, } # Lit is disabled by default, then enabled via the `lit` command. # Or it can be permanently enabled, without the use of the `lit` command. @enabled = false ## # FLAGS. # # Flag defaults when not supplied via command line. ## # Array of types to filter by, for example... [:warn, :error, :fail] @type = nil # Boolean on whether or not to step through each lit() breakpoint. @step = false # Integer or float representing amount of seconds to delay each lit() by. @delay = 0 cli_configure() end |
Instance Attribute Details
#delay ⇒ Object
Returns the value of attribute delay.
28 29 30 |
# File 'lib/config.rb', line 28 def delay @delay end |
#enabled ⇒ Object
Returns the value of attribute enabled.
24 25 26 |
# File 'lib/config.rb', line 24 def enabled @enabled end |
#step ⇒ Object
Returns the value of attribute step.
27 28 29 |
# File 'lib/config.rb', line 27 def step @step end |
#type ⇒ Object
Returns the value of attribute type.
26 27 28 |
# File 'lib/config.rb', line 26 def type @type end |
#types ⇒ Object
Returns the value of attribute types.
25 26 27 |
# File 'lib/config.rb', line 25 def types @types end |
Instance Method Details
#cli_configure ⇒ Object
Override config from command line.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/config.rb', line 64 def cli_configure() @enabled = true if ENV['LIT_ENABLED'] == 'true' # Convert flag string to hash. flags = {} if ENV['LIT_FLAGS'] && !ENV['LIT_FLAGS'].empty? ENV['LIT_FLAGS'].split().each do |flag| values = flag.split('=') key = values.shift.to_sym # No arguments. if values.empty? flags[key] = nil else args = values.pop.split(',') # Single argument. if args.count == 1 flags[key] = args.first # Multiple arguments. else flags[key] = args end end end end @step = true if flags.has_key? :step @type = Array(flags[:type]).map(&:to_sym) if valid? flags, :type @delay = flags[:delay].to_f if valid? flags, :delay end |
#valid?(flags, flag) ⇒ Boolean
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/config.rb', line 96 def valid? flags, flag # Has flag even been entered on the command line? unless flags.has_key? flag return false end if flags[flag].nil? error = "🔥 ERROR: Invalid argument for @#{flag}." unless @@errors.include? error @@errors.add error puts error end return false end true end |