Class: Skein::Config
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Skein::Config
- Defined in:
- lib/skein/config.rb
Constant Summary collapse
- CONFIG_PATH_DEFAULT =
Constants ============================================================
'config/skein.yml'.freeze
- ENV_DEFAULT =
'development'.freeze
- DRIVERS =
{ bunny: 'Bunny', march_hare: 'MarchHare' }.freeze
- DRIVER_PLATFORM_DEFAULT =
Hash.new(:bunny).merge( "java" => :march_hare ).freeze
- DRIVER_DEFAULT =
( DRIVERS.find do |name, const| const_defined?(const) end || [ ] )[0]
- DEFAULTS =
{ host: '127.0.0.1', port: 5672, username: 'guest', password: 'guest', driver: DRIVER_DEFAULT, namespace: nil }.freeze
Class Method Summary collapse
- .env ⇒ Object
- .exist? ⇒ Boolean
- .path ⇒ Object
-
.root ⇒ Object
Class Methods ========================================================.
Instance Method Summary collapse
-
#initialize(options = nil) ⇒ Config
constructor
Instance Methods =====================================================.
Constructor Details
#initialize(options = nil) ⇒ Config
Instance Methods =====================================================
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/skein/config.rb', line 63 def initialize( = nil) config_path = nil case () when String if (File.exist?()) config_path = end when Hash super( DEFAULTS.merge( Hash[ .map do |k, v| [ k.nil? ? nil : k.to_sym, v ] end ] ) ) return when false, :default # Ignore configuration file, use defaults else config_path = File.('config/skein.yml', self.class.root) end if (config_path and File.exist?(config_path)) super(DEFAULTS.merge( YAML.load_file(config_path, aliases: true)[self.class.env] || { } )) else super(DEFAULTS) end end |
Class Method Details
.env ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/skein/config.rb', line 45 def self.env if (defined?(Rails)) Rails.env.to_s else ENV['RAILS_ENV'] || ENV_DEFAULT end end |
.exist? ⇒ Boolean
57 58 59 |
# File 'lib/skein/config.rb', line 57 def self.exist? File.exist?(self.path) end |
.path ⇒ Object
53 54 55 |
# File 'lib/skein/config.rb', line 53 def self.path File.(CONFIG_PATH_DEFAULT, self.root) end |
.root ⇒ Object
Class Methods ========================================================
37 38 39 40 41 42 43 |
# File 'lib/skein/config.rb', line 37 def self.root if (defined?(Rails)) Rails.root else Dir.pwd end end |