Class: Squid::Configuration
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Squid::Configuration
- 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.
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
-
#initialize ⇒ Configuration
constructor
Initialize the global configuration settings.
Constructor Details
#initialize ⇒ Configuration
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, | var = "squid_#{key}".upcase value = ENV.fetch var, .fetch(:default, '') public_send "#{key}=", [: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 |
.boolean ⇒ Object
31 32 33 |
# File 'lib/squid/configuration.rb', line 31 def self.boolean -> (value) { %w(1 t T true TRUE).include? value } end |
.float ⇒ Object
43 44 45 |
# File 'lib/squid/configuration.rb', line 43 def self.float -> (value) { value.to_f } end |
.integer ⇒ Object
35 36 37 |
# File 'lib/squid/configuration.rb', line 35 def self.integer -> (value) { value.to_i } end |
.symbol ⇒ Object
39 40 41 |
# File 'lib/squid/configuration.rb', line 39 def self.symbol -> (value) { value.to_sym } end |