class Broken::Config
Default config that can be overridden from the command line or application.
@usage:
Broken.configure do |config| config.<property> = <value> end
@precedence:
3. Defaults - initialize() 2. Application - Broken.configure() 1. Command line flags - cli_configure()
Attributes
delay[RW]
enabled[RW]
status[RW]
statuses[RW]
step[RW]
Flags.
type[RW]
types[RW]
Public Class Methods
new()
click to toggle source
# 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 # Broken is disabled by default, then enabled via the `broken` command. # Or it can be permanently enabled, without the use of the `broken` 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 broken() by. @delay = 0 ## # PRIVATE. ## # Boolean on whether or not to step through each broken() breakpoint. # Setting to true here wont enable Pry, best to enable via command line. @step = false cli_configure() end
Public Instance Methods
cli_configure()
click to toggle source
Override config from command line.
# File lib/config.rb, line 77 def cli_configure() # Enable broken via the command line. @enabled = true if ENV['BROKEN_ENABLED'] && ENV['BROKEN_ENABLED'].to_i >= (Time.now.to_i() - 1) return unless @enabled # Convert flag string to hash. flags = {} if ENV['BROKEN_FLAGS'] && !ENV['BROKEN_FLAGS'].empty? ENV['BROKEN_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)
click to toggle source
# 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