Class: Padrino::Env::Application
- Inherits:
-
Object
- Object
- Padrino::Env::Application
- Defined in:
- lib/padrino/env.rb
Class Method Summary collapse
Instance Method Summary collapse
- #configuration ⇒ Object
- #each(&block) ⇒ Object
- #environment ⇒ Object
- #environment_configuration ⇒ Object
- #global_configuration ⇒ Object
-
#initialize(options = {}) ⇒ Application
constructor
A new instance of Application.
- #load ⇒ Object
- #non_string_configuration!(value) ⇒ Object
- #parse(path) ⇒ Object
- #path ⇒ Object
- #raw_configuration ⇒ Object
- #set(key, value) ⇒ Object
- #skip?(key) ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Application
Returns a new instance of Application.
14 15 16 17 |
# File 'lib/padrino/env.rb', line 14 def initialize( = {}) @path = .fetch(:path, 'config/application.yml') @environment = .fetch(:environment, Padrino.env) end |
Class Method Details
.load(options = {}) ⇒ Object
10 11 12 |
# File 'lib/padrino/env.rb', line 10 def self.load( = {}) new().load end |
Instance Method Details
#configuration ⇒ Object
33 34 35 |
# File 'lib/padrino/env.rb', line 33 def configuration global_configuration.merge(environment_configuration) end |
#each(&block) ⇒ Object
43 44 45 |
# File 'lib/padrino/env.rb', line 43 def each(&block) configuration.each(&block) end |
#environment ⇒ Object
29 30 31 |
# File 'lib/padrino/env.rb', line 29 def environment @environment.to_s end |
#environment_configuration ⇒ Object
59 60 61 |
# File 'lib/padrino/env.rb', line 59 def environment_configuration raw_configuration.fetch(environment) { {} } end |
#global_configuration ⇒ Object
55 56 57 |
# File 'lib/padrino/env.rb', line 55 def global_configuration raw_configuration.reject { |_, value| value.is_a?(Hash) } end |
#load ⇒ Object
37 38 39 40 41 |
# File 'lib/padrino/env.rb', line 37 def load each do |key, value| set(key, value) unless skip?(key) end end |
#non_string_configuration!(value) ⇒ Object
68 69 70 |
# File 'lib/padrino/env.rb', line 68 def non_string_configuration!(value) warn "WARNING: Use strings for Figaro configuration. #{value.inspect} was converted to #{value.to_s.inspect}." end |
#parse(path) ⇒ Object
63 64 65 66 |
# File 'lib/padrino/env.rb', line 63 def parse(path) return (YAML.load(ERB.new(File.read(path)).result) || {}) if File.exist?(path) {} end |
#raw_configuration ⇒ Object
51 52 53 |
# File 'lib/padrino/env.rb', line 51 def raw_configuration @parsed ||= parse(path) end |
#set(key, value) ⇒ Object
19 20 21 22 23 |
# File 'lib/padrino/env.rb', line 19 def set(key, value) non_string_configuration!(key) unless key.is_a?(String) non_string_configuration!(value) unless value.is_a?(String) ::ENV[key.to_s] = value.to_s end |
#skip?(key) ⇒ Boolean
25 26 27 |
# File 'lib/padrino/env.rb', line 25 def skip?(key) ::ENV.key?(key.to_s) end |