Class: Squid::Configuration

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/squid/configuration.rb

Overview

Provides an object to store global configuration settings.

This class is typically not used directly, but by calling Squid.configure, which creates and updates a single instance of Configuration.

An alternative way to set global configuration settings is by storing them in the following environment variables:

  • SQUID_HEIGHT to store the default graph height

In case both methods are used together, Squid.configure takes precedence.

Examples:

Set the default height for Squid graphs:

Squid.configure do |config|
  config.height = 150
  config.steps = 4
end

Set the default graph height:

ENV['SQUID_HEIGHT'] =  '150'
ENV['SQUID_GRIDLINES'] =  '4'

See Also:

Constant Summary collapse

COLORS =
'2e578c 5d9648 e7a13d bc2d30 6f3d79 7d807f'
ATTRIBUTES =
{
  baseline:     {default: 'true',      as: boolean},
  border:       {default: 'false',     as: boolean},
  chart:        {default: 'true',      as: boolean},
  colors:       {default: COLORS,      as: array},
  every:        {default: '1',         as: integer},
  format:       {default: 'integer',   as: symbol},
  height:       {default: '250',       as: float},
  labels:       {default: 'false',     as: boolean},
  legend:       {default: 'true',      as: boolean},
  line_widths:  {default: '3',         as: integer},
  steps:        {default: '4',         as: integer},
  ticks:        {default: 'true',      as: boolean},
  type:         {default: 'column',    as: symbol},
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initialize the global configuration settings.


72
73
74
75
76
77
78
# File 'lib/squid/configuration.rb', line 72

def initialize
  ATTRIBUTES.each do |key, options|
    var = "squid_#{key}".upcase
    value = ENV.fetch var, options[:default]
    public_send "#{key}=", options[:as].call(value)
  end
end

Class Method Details

.arrayObject


49
50
51
# File 'lib/squid/configuration.rb', line 49

def self.array
  -> (value) { value.split }
end

.booleanObject


33
34
35
# File 'lib/squid/configuration.rb', line 33

def self.boolean
  -> (value) { %w(1 t T true TRUE).include? value }
end

.floatObject


45
46
47
# File 'lib/squid/configuration.rb', line 45

def self.float
  -> (value) { value.to_f }
end

.integerObject


37
38
39
# File 'lib/squid/configuration.rb', line 37

def self.integer
  -> (value) { value.to_i }
end

.symbolObject


41
42
43
# File 'lib/squid/configuration.rb', line 41

def self.symbol
  -> (value) { value.to_sym }
end