Sha256: c23f50b01e53bbfc2803b0bf7dad9c3c5f80636ae0e1f91b295160f2b70d3f4a

Contents?: true

Size: 940 Bytes

Versions: 2

Compression:

Stored size: 940 Bytes

Contents

module Scales
  module Config
    require 'ostruct'
    
    DEFAULTS = {
      :host       => "localhost",
      :port       => 6379,
      :password   => nil,
      :database   => 0,
      :partials   => false
    }
    
    @@pwd = "."
    CONFIG_PATHS  = ['config/cache.yml', 'cache.yml']
    
    class << self
      
      def config
        @@config ||= OpenStruct.new DEFAULTS.merge(load!)
      end
      
      def reset!
        @@config = nil
      end
      
      def load!
        load_paths = CONFIG_PATHS.map{ |path| File.exists?(File.join(@@pwd, path)) }
        return {} unless load_paths.any?
        
        cache   = File.join(@@pwd, CONFIG_PATHS[load_paths.index(true)])
        config  = YAML.load_file(cache)[Scales.env]
        
        Hash[config.map{|(k,v)| [k.to_sym,v]}]
      end
      
      def pwd=(pwd)
        @@pwd = pwd
      end
      
      def pwd
        @@pwd
      end
      
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
scales-core-0.0.1.beta.2 lib/scales-core/config.rb
scales-core-0.0.1.beta.1 lib/scales-core/config.rb