Class: Papermill::Configurator
- Inherits:
-
Object
- Object
- Papermill::Configurator
- Defined in:
- lib/papermill-agent/configurator.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #endpoint ⇒ Object
-
#initialize(config_source = 'config/papermill.yml') ⇒ Configurator
constructor
A new instance of Configurator.
- #live_mode ⇒ Object
-
#load_config(config_source) ⇒ Object
Loads the papermill configuration.
-
#setting(name) ⇒ Object
returns the value of a setting for the current environment or nil, if it does not exist.
- #token ⇒ Object
Constructor Details
#initialize(config_source = 'config/papermill.yml') ⇒ Configurator
Returns a new instance of Configurator.
8 9 10 11 |
# File 'lib/papermill-agent/configurator.rb', line 8 def initialize(config_source = 'config/papermill.yml') load_config(config_source) after_init end |
Instance Attribute Details
#environment ⇒ Object
62 63 64 |
# File 'lib/papermill-agent/configurator.rb', line 62 def environment @environment ||= (defined?(Rails) && Rails.env) || ENV['RACK_ENV'] || 'development' end |
Instance Method Details
#endpoint ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/papermill-agent/configurator.rb', line 39 def endpoint if setting('endpoint') && environment != 'production' config[environment]['endpoint'] else API_ENDPOINT end end |
#live_mode ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/papermill-agent/configurator.rb', line 53 def live_mode if has_config_for_environment?('live_mode') setting('live_mode') else # default to true for production environments, false otherwise environment == 'production' ? true : false end end |
#load_config(config_source) ⇒ Object
Loads the papermill configuration.
By default, the papermill configuration is read from a yaml file located at ./config/papermill.yml. Still, the configuration source can either be a yaml file of any name or a ruby hash.
If the configuration file cannot be found, the agent will be disabled.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/papermill-agent/configurator.rb', line 20 def load_config(config_source) @config = case when config_source.class == String begin YAML.load_file(config_source) rescue Errno::ENOENT => e disable_agent Agent.instance.logger.info "The papermill configuration file does not exist. The papermill agent is disabled." return nil end when config_source.class == Hash config_source end end |
#setting(name) ⇒ Object
returns the value of a setting for the current environment or nil, if it does not exist.
49 50 51 |
# File 'lib/papermill-agent/configurator.rb', line 49 def setting(name) config[environment] && config[environment][name] end |
#token ⇒ Object
35 36 37 |
# File 'lib/papermill-agent/configurator.rb', line 35 def token (config && config.has_key?('token')) ? config['token'] : nil end |