class Bovem::Configuration

This class holds the configuration of an application.

Extend this class and add valid properties via {property property} method. Example:

“`ruby class MyConfiguration << Bovem::Configuration

property :property, default: "VALUE"

end

# Configuration file config.property = “VALUE” “`

@attribute [r] i18n

@return [I18n] A i18n helper.

Attributes

i18n[R]

Public Class Methods

new(file = nil, overrides = {}, logger = nil) click to toggle source

Creates a new configuration.

A configuration file is a plain Ruby file with a top-level {Configuration config} object.

@param file [String] The file to read. @param overrides [Hash] A set of values which override those set in the configuration file. @param logger [Logger] The logger to use for notifications. @see parse

Calls superclass method
# File lib/bovem/configuration.rb, line 35
def initialize(file = nil, overrides = {}, logger = nil)
  super()

  @i18n = Bovem::I18n.new(root: "bovem.configuration", path: Bovem::Application::LOCALE_ROOT)
  parse(file, overrides, logger)
end

Public Instance Methods

parse(file = nil, overrides = {}, logger = nil) click to toggle source

Parses a configuration file.

A configuration file is a plain Ruby file with a top-level {Configuration config} object.

Example:

“`ruby config.property = “VALUE” “`

@param file [String] The file to read. @param logger [Logger] The logger to use for notifications. @param overrides [Hash] A set of values which override those set in the configuration file.

# File lib/bovem/configuration.rb, line 55
def parse(file = nil, overrides = {}, logger = nil)
  file = file.present? ? File.expand_path(file) : nil

  if file
    raise(Bovem::Errors::InvalidConfiguration, i18n.not_found(file)) unless File.readable?(file)
    read_configuration_file(file, logger)
  end

  # Apply overrides
  overrides.each_pair { |k, v| send("#{k}=", v) if respond_to?("#{k}=") } if overrides.is_a?(::Hash)

  self
end