Class: Yacht::Loader
- Inherits:
-
Object
- Object
- Yacht::Loader
- Defined in:
- lib/yacht/loader.rb,
lib/yacht/rails.rb,
lib/yacht/classy_struct.rb
Overview
TODO: Rename YachtLoader to Yacht and somehow incorporate ClassyStruct
Class Attribute Summary collapse
- .dir ⇒ Object
-
.environment ⇒ Object
use the current rails environment by default.
Class Method Summary collapse
- .all ⇒ Object
- .base_config ⇒ Object
- .classy_struct_instance ⇒ Object
- .config_file_for(config_type) ⇒ Object
- .full_file_path_for_config(config_type) ⇒ Object
- .local_config ⇒ Object
- .to_classy_struct(opts = {}) ⇒ Object
- .to_hash(opts = {}) ⇒ Object
- .valid_config_types ⇒ Object
- .whitelist ⇒ Object
Class Attribute Details
.dir ⇒ Object
8 9 10 |
# File 'lib/yacht/rails.rb', line 8 def dir @dir ||= Rails.root.join('config', 'yacht') end |
.environment ⇒ Object
use the current rails environment by default
4 5 6 |
# File 'lib/yacht/rails.rb', line 4 def environment @environment ||= Rails.env end |
Class Method Details
.all ⇒ Object
29 30 31 |
# File 'lib/yacht/loader.rb', line 29 def all chain_configs(base_config, self.environment).deep_merge(local_config) end |
.base_config ⇒ Object
48 49 50 |
# File 'lib/yacht/loader.rb', line 48 def base_config load_config_file(:base) || raise( Yacht::LoadError.new("Couldn't load base config") ) end |
.classy_struct_instance ⇒ Object
6 7 8 |
# File 'lib/yacht/classy_struct.rb', line 6 def classy_struct_instance @classy_struct_instance ||= ClassyStruct.new end |
.config_file_for(config_type) ⇒ Object
19 20 21 22 23 |
# File 'lib/yacht/loader.rb', line 19 def config_file_for(config_type) raise Yacht::LoadError.new "#{config_type} is not a valid config type" unless valid_config_types.include?(config_type.to_s) full_file_path_for_config(config_type) end |
.full_file_path_for_config(config_type) ⇒ Object
12 13 14 |
# File 'lib/yacht/rails.rb', line 12 def full_file_path_for_config(config_type) dir.join("#{config_type}.yml") end |
.local_config ⇒ Object
52 53 54 |
# File 'lib/yacht/loader.rb', line 52 def local_config load_config_file(:local) || {} end |
.to_classy_struct(opts = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/yacht/classy_struct.rb', line 10 def to_classy_struct(opts={}) classy_struct_instance.new( self.to_hash(opts) ) rescue StandardError => e # don't do anything to our own custom errors if e.is_a? Yacht::LoadError raise e else raise Yacht::LoadError.new("Error creating ClassyStruct: #{e.}") end end |
.to_hash(opts = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/yacht/loader.rb', line 33 def to_hash(opts={}) opts[:apply_whitelist?] ||= false unless opts.has_key?(:apply_whitelist?) self.environment = opts[:env] if opts.has_key?(:env) if opts[:apply_whitelist?] all.slice(*whitelist) else all end end |
.valid_config_types ⇒ Object
25 26 27 |
# File 'lib/yacht/loader.rb', line 25 def valid_config_types %w( base local whitelist ) end |