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

ATTRIBUTES =
{
  baseline:     {as: boolean,        default: 'true'},
  border:       {as: boolean,        default: 'false'},
  chart:        {as: boolean,        default: 'true'},
  colors:       {as: array},
  every:        {as: integer,        default: '1'},
  formats:      {as: array(symbol)},
  height:       {as: float,          default: '250'},
  labels:       {as: array(boolean)},
  legend:       {as: boolean,        default: 'true'},
  line_widths:  {as: array(float)},
  steps:        {as: integer,        default: '4'},
  ticks:        {as: boolean,        default: 'true'},
  type:         {as: symbol,         default: 'column'},
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initialize the global configuration settings.



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

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

Class Method Details

.array(proc = nil) ⇒ Object



47
48
49
# File 'lib/squid/configuration.rb', line 47

def self.array(proc = nil)
  -> (values) { values.split.map{|value| proc ? proc.call(value) : value} }
end

.booleanObject



31
32
33
# File 'lib/squid/configuration.rb', line 31

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

.floatObject



43
44
45
# File 'lib/squid/configuration.rb', line 43

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

.integerObject



35
36
37
# File 'lib/squid/configuration.rb', line 35

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

.symbolObject



39
40
41
# File 'lib/squid/configuration.rb', line 39

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