Class: SelectPdfApi::YamlConfig
- Inherits:
-
Object
- Object
- SelectPdfApi::YamlConfig
- Defined in:
- lib/select_pdf_api/yaml_config.rb
Overview
Default config class used to store API options and key.
Instance Attribute Summary collapse
-
#data ⇒ Object
API Options Hash.
Instance Method Summary collapse
-
#initialize(filename) ⇒ YamlConfig
constructor
A new instance of YamlConfig.
-
#load_config(filename) ⇒ Hash
Options loaded from config file.
-
#options ⇒ Hash
Required by all config classes as the common interface for the main class.
Constructor Details
#initialize(filename) ⇒ YamlConfig
Returns a new instance of YamlConfig.
10 11 12 |
# File 'lib/select_pdf_api/yaml_config.rb', line 10 def initialize(config_file="select-pdf-config") load_config config_file end |
Instance Attribute Details
#data ⇒ Object
API Options Hash
6 7 8 |
# File 'lib/select_pdf_api/yaml_config.rb', line 6 def data @data end |
Instance Method Details
#load_config(filename) ⇒ Hash
Returns Options loaded from config file.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/select_pdf_api/yaml_config.rb', line 19 def load_config(config_file) config_file_with_path = File.join(File.(File.join('config')), "#{config_file}.yml") raise SelectPdfApi::ConfigError, "Config file #{config_file_with_path} does not exist." unless File.exist? config_file_with_path @data = {} @data = YAML::load_file(config_file_with_path) raise SelectPdfApi::ConfigError, "Error loading values from #{config_file_with_path}" unless @data @data end |
#options ⇒ Hash
Required by all config classes as the common interface for the main class.
36 37 38 |
# File 'lib/select_pdf_api/yaml_config.rb', line 36 def @data.delete_if{|k, v| v.empty?} end |