Class: LitCLI::Config
- Inherits:
-
Object
- Object
- LitCLI::Config
- Defined in:
- lib/config.rb
Overview
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.
-
#status ⇒ Object
Returns the value of attribute status.
-
#statuses ⇒ Object
Returns the value of attribute statuses.
-
#step ⇒ Object
Flags.
-
#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.
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 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/config.rb', line 33 def initialize() @statuses = { :info => { icon: "ℹ", color: :blue, styles: [:upcase] }, :pass => { icon: "✔", color: :green, styles: [:upcase] }, :warn => { icon: "⚠", color: :yellow, styles: [:upcase] }, :fail => { icon: "⨯", color: :red, styles: [:upcase] }, :error => { icon: "!", color: :red, styles: [:upcase] }, :debug => { icon: "?", color: :purple, styles: [:upcase] }, } @types = nil # 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 statuses to filter by, for example: [:warn, :error, :fail] @status = nil # Array of types to filter by, for example: [:cat, :dog, :tree] @type = nil # Integer or float representing amount of seconds to delay each lit() by. @delay = 0 ## # PRIVATE. ## # Boolean on whether or not to step through each lit() breakpoint. # Setting to true here wont enable Pry, best to enable via command line. @step = false cli_configure() end |
Instance Attribute Details
#delay ⇒ Object
Returns the value of attribute delay.
31 32 33 |
# File 'lib/config.rb', line 31 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 |
#status ⇒ Object
Returns the value of attribute status.
29 30 31 |
# File 'lib/config.rb', line 29 def status @status end |
#statuses ⇒ Object
Returns the value of attribute statuses.
25 26 27 |
# File 'lib/config.rb', line 25 def statuses @statuses end |
#step ⇒ Object
Flags.
28 29 30 |
# File 'lib/config.rb', line 28 def step @step end |
#type ⇒ Object
Returns the value of attribute type.
30 31 32 |
# File 'lib/config.rb', line 30 def type @type end |
#types ⇒ Object
Returns the value of attribute types.
26 27 28 |
# File 'lib/config.rb', line 26 def types @types end |
Instance Method Details
#cli_configure ⇒ Object
Override config from command line.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/config.rb', line 77 def cli_configure() # Enable lit via the command line. @enabled = true if ENV['LIT_ENABLED'] && ENV['LIT_ENABLED'].to_i >= (Time.now.to_i() - 1) return unless @enabled # 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 @status = Array(flags[:status]).map(&:to_sym) if valid? flags, :status @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
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/config.rb', line 113 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 |