Class: JayAPI::Configuration
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- JayAPI::Configuration
- Extended by:
- Forwardable
- Defined in:
- lib/jay_api/configuration.rb,
lib/jay_api/mergeables/merge_selector.rb
Overview
This class declaration serves as an extension of the already defined JayAPI::Configuration class.
Direct Known Subclasses
Class Method Summary collapse
-
.from_file(file_name) ⇒ JayAPI::Configuration
Loads the configuration from the given file.
-
.from_string(yaml) ⇒ JayAPI::Configuration
Loads the configuration from the given YAML string.
Instance Method Summary collapse
-
#deep_to_h ⇒ Hash
Recursively converts the receiver into a standard Hash.
-
#keys ⇒ Array<Object>
An array with the keys (generally the name of the attributes) that the configuration object has.
-
#to_yaml ⇒ String
The configuration in the YAML format.
-
#with_merge_selector ⇒ JayAPI::Mergeables::MergeSelector::Configuration
A Configuration object that contains the merging functionality.
Class Method Details
.from_file(file_name) ⇒ JayAPI::Configuration
Loads the configuration from the given file.
27 28 29 |
# File 'lib/jay_api/configuration.rb', line 27 def self.from_file(file_name) from_string(File.read(file_name)) end |
.from_string(yaml) ⇒ JayAPI::Configuration
Loads the configuration from the given YAML string.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jay_api/configuration.rb', line 36 def self.from_string(yaml) yaml = ERB.new(yaml).result config = YAML.safe_load(yaml, permitted_classes: [Symbol]) unless config.is_a?(Hash) raise JayAPI::Errors::ConfigurationError.new( "Jay's configuration should be a set of key-value pairs.", yaml ) end from_hash(config) end |
Instance Method Details
#deep_to_h ⇒ Hash
Recursively converts the receiver into a standard Hash
83 84 85 |
# File 'lib/jay_api/configuration.rb', line 83 def deep_to_h to_h { |key, value| [key, value_for_h(value)] } end |
#keys ⇒ Array<Object>
Returns An array with the keys (generally the name of the attributes) that the configuration object has.
94 95 96 |
# File 'lib/jay_api/configuration.rb', line 94 def keys @table.keys end |
#to_yaml ⇒ String
Returns The configuration in the YAML format.
88 89 90 |
# File 'lib/jay_api/configuration.rb', line 88 def to_yaml YAML.dump(deep_to_h.deep_stringify_keys) end |
#with_merge_selector ⇒ JayAPI::Mergeables::MergeSelector::Configuration
Returns A Configuration object that contains the merging functionality.
11 12 13 |
# File 'lib/jay_api/mergeables/merge_selector.rb', line 11 def with_merge_selector JayAPI::Mergeables::MergeSelector::Configuration.from_hash(deep_to_h) end |