Class: SiteSettings::YamlLoader
- Inherits:
-
Object
- Object
- SiteSettings::YamlLoader
- Defined in:
- lib/site_settings/yaml_loader.rb
Instance Method Summary collapse
-
#initialize(file) ⇒ YamlLoader
constructor
A new instance of YamlLoader.
- #load ⇒ Object
Constructor Details
#initialize(file) ⇒ YamlLoader
Returns a new instance of YamlLoader.
7 8 9 |
# File 'lib/site_settings/yaml_loader.rb', line 7 def initialize(file) @file = file end |
Instance Method Details
#load ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/site_settings/yaml_loader.rb', line 11 def load yaml = load_yaml(@file) yaml.each_key do |category| yaml[category].each do |setting_name, hash| if hash.is_a?(Hash) # Get default value for the site setting: value = hash.delete("default") if value.nil? raise StandardError, "The site setting `#{setting_name}` in '#{@file}' is missing default value." end if hash.values_at("min", "max").any? && hash["validator"].present? raise StandardError, "The site setting `#{setting_name}` in '#{@file}' will have it's min/max validation ignored because there is a validator also specified." end yield category, setting_name, value, hash.deep_symbolize_keys! else # Simplest case. site_setting_name: 'default value' yield category, setting_name, hash, {} end end end end |