Class: SelectPdfApi::YamlConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/select_pdf_api/yaml_config.rb

Overview

Default config class used to store API options and key.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ YamlConfig

Returns a new instance of YamlConfig.

Parameters:

  • filename (String)

    Config file to be loaded.



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

#dataObject

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.

Parameters:

  • filename (String)

    Config file to be loaded.

Returns:

  • (Hash)

    Options loaded from config file.

Raises:



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.expand_path(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

#optionsHash

Required by all config classes as the common interface for the main class.

Returns:

  • (Hash)

    Collection of options loaded from the config file.



36
37
38
# File 'lib/select_pdf_api/yaml_config.rb', line 36

def options
	@data.delete_if{|k, v| v.empty?}
end