class RSpectacles::Config

Public Class Methods

new() click to toggle source
# File lib/rspectacles/config.rb, line 8
def initialize
  @opts = OpenStruct.new defaults.merge(yml)
end

Public Instance Methods

defaults() click to toggle source
# File lib/rspectacles/config.rb, line 12
def defaults
  {
    batch_size: (ENV['RSPECTACLES_BATCH_SIZE'] || 1000).to_i,
    last_run_primary_key: ENV['RSPECTACLES_RUN_KEY'] || ENV['CIRCLE_BUILD_NUM'] || SecureRandom.hex,
    timeout: (ENV['RSPECTACLES_TIMEOUT'] || 15).to_i,
    rspectacles_url: ENV['RSPECTACLES_URL']
  }
end
method_missing(method, *args) click to toggle source
# File lib/rspectacles/config.rb, line 25
def method_missing(method, *args)
  @opts.public_send method, *args
end
timeout() click to toggle source
# File lib/rspectacles/config.rb, line 21
def timeout
  @opts[:timeout]
end

Private Instance Methods

sanitize(hash) click to toggle source
# File lib/rspectacles/config.rb, line 49
def sanitize(hash)
  hash.each_with_object({}) { |(key, value), memo| memo[key.to_sym] = value }
end
yml() click to toggle source
# File lib/rspectacles/config.rb, line 39
def yml
  res = if yml_exists?
          @yml ||= ::YAML.safe_load(::ERB.new(IO.read(yml_path)).result)
        else
          {}
        end

  sanitize(res)
end
yml_exists?() click to toggle source
# File lib/rspectacles/config.rb, line 35
def yml_exists?
  yml_path && ::File.exist?(yml_path)
end
yml_path() click to toggle source
# File lib/rspectacles/config.rb, line 31
def yml_path
  ::File.expand_path(ENV['RSPECTACLES_CONFIG']) if ENV['RSPECTACLES_CONFIG']
end