Class: Bovem::Configuration
- Inherits:
-
Lazier::Configuration
- Object
- Lazier::Configuration
- Bovem::Configuration
- Defined in:
- lib/bovem/configuration.rb
Overview
This class holds the configuration of an application.
Extend this class and add valid properties via property method. Example:
```ruby class MyConfiguration « Bovem::Configuration property :property, default: “VALUE” end
Configuration file
config.property = “VALUE” ```
Instance Method Summary (collapse)
-
- (Configuration) initialize(file = nil, overrides = {}, logger = nil)
constructor
Creates a new configuration.
-
- (Object) parse(file = nil, overrides = {}, logger = nil)
Parses a configuration file.
Constructor Details
- (Configuration) initialize(file = nil, overrides = {}, logger = nil)
Creates a new configuration.
A configuration file is a plain Ruby file with a top-level config object.
30 31 32 33 34 35 |
# File 'lib/bovem/configuration.rb', line 30 def initialize(file = nil, overrides = {}, logger = nil) super() i18n_setup(:bovem, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")) parse(file, overrides, logger) end |
Instance Method Details
- (Object) parse(file = nil, overrides = {}, logger = nil)
Parses a configuration file.
A configuration file is a plain Ruby file with a top-level config object.
Example:
ruby
config.property = "VALUE"
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/bovem/configuration.rb', line 50 def parse(file = nil, overrides = {}, logger = nil) file = file.present? ? File.(file) : nil if file then if File.readable?(file) then read_configuration_file(file, logger) else raise Bovem::Errors::InvalidConfiguration.new(i18n.configuration.not_found(file)) end end # Apply overrides overrides.each_pair { |k, v| send("#{k}=", v) if self.respond_to?("#{k}=") } if overrides.is_a?(::Hash) self end |