Class: RubyRabbitmqJanus::Tools::Config
- Inherits:
-
Object
- Object
- RubyRabbitmqJanus::Tools::Config
- Includes:
- Singleton
- Defined in:
- lib/rrj/tools/config.rb
Overview
Loading a yaml file for apply a configuration to gem.
Constant Summary collapse
- DEFAULT_PATH =
Define a default path to file configuration
File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
- DEFAULT_CONF =
Define a default name to file configuration
'config/default.yml'- CUSTOMIZE_CONF =
Define a default override file configuration
'config/ruby-rabbitmq-janus.yml'
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#conf_customize ⇒ Object
private
Load customize configuration file if exist.
-
#conf_default ⇒ Object
private
Load default configuration if customize configuration doesn't exist.
-
#define_log_level_used ⇒ Object
private
Define log lvel used in this gem.
-
#initialize ⇒ Config
constructor
Initialize configuration file default or customize if exist.
-
#load_configuration(file) ⇒ Yaml
private
Load configuration file yaml :reek:UtilityFunction { public_methods_only: true }.
Constructor Details
#initialize ⇒ Config
Initialize configuration file default or customize if exist
22 23 24 25 26 27 |
# File 'lib/rrj/tools/config.rb', line 22 def initialize @options = nil conf_customize conf_default define_log_level_used end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/rrj/tools/config.rb', line 10 def @options end |
Instance Method Details
#conf_customize ⇒ Object (private)
Load customize configuration file if exist
43 44 45 46 |
# File 'lib/rrj/tools/config.rb', line 43 def conf_customize file = File.join(Dir.pwd, CUSTOMIZE_CONF) @options = load_configuration(file) if File.exist?(file) end |
#conf_default ⇒ Object (private)
Load default configuration if customize configuration doesn't exist
49 50 51 52 |
# File 'lib/rrj/tools/config.rb', line 49 def conf_default file = File.join(DEFAULT_PATH, DEFAULT_CONF) @options ||= load_configuration(file) end |
#define_log_level_used ⇒ Object (private)
Define log lvel used in this gem
55 56 57 58 59 60 |
# File 'lib/rrj/tools/config.rb', line 55 def define_log_level_used Tools::Log.instance.level = \ Tools::Log::LEVELS[@options['gem']['log']['level'].to_sym] rescue raise Errors::LevelNotDefine end |
#load_configuration(file) ⇒ Yaml (private)
Load configuration file yaml :reek:UtilityFunction { public_methods_only: true }
35 36 37 38 39 40 |
# File 'lib/rrj/tools/config.rb', line 35 def load_configuration(file) Tools::Log.instance.info("Loading configuration file : #{file}") YAML.load(File.read(file)) rescue raise Errors::ConfigFileNotFound, file end |