Class: RailsSettings::Default
- Inherits:
-
Hash
- Object
- Hash
- RailsSettings::Default
- Defined in:
- lib/rails-settings/default.rb
Defined Under Namespace
Classes: MissingKey
Class Method Summary collapse
- .[](key) ⇒ Object
- .enabled? ⇒ Boolean
- .instance ⇒ Object
- .source(value = nil) ⇒ Object
- .source_path ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Default
constructor
A new instance of Default.
Constructor Details
#initialize ⇒ Default
Returns a new instance of Default.
33 34 35 36 37 38 |
# File 'lib/rails-settings/default.rb', line 33 def initialize content = open(self.class.source_path).read hash = content.empty? ? {} : YAML.load(ERB.new(content).result).to_hash hash = hash[Sinatra::Application.environment.to_s] || {} replace hash end |
Class Method Details
.[](key) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/rails-settings/default.rb', line 20 def [](key) # foo.bar.dar Nested fetch value return instance[key] if instance.key?(key) keys = key.to_s.split(".") instance.dig(*keys) end |
.enabled? ⇒ Boolean
8 9 10 |
# File 'lib/rails-settings/default.rb', line 8 def enabled? source_path && File.exist?(source_path) end |
.instance ⇒ Object
27 28 29 30 |
# File 'lib/rails-settings/default.rb', line 27 def instance return @instance if defined? @instance @instance = new end |
.source(value = nil) ⇒ Object
12 13 14 |
# File 'lib/rails-settings/default.rb', line 12 def source(value = nil) @source ||= value end |
.source_path ⇒ Object
16 17 18 |
# File 'lib/rails-settings/default.rb', line 16 def source_path @source || "config/app.yml" end |