Sha256: 7ea5523799f00c5c4cf2ebebc755d67bdfbbd1e6d6ae2f8f9de3fe30e89d1fa3

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

module Baurets
  module Optionsful
    class Config

      DEFAULT = { :link => false, :host => 'auto', :base_path =>  "/optionsful", :propagate => true }

      def initialize(file = nil, options = {})
        unless file.nil?
          @config = load_from_file(file, get_env)
        else
          begin
            if (defined? Rails && File.exist?(File.join(Rails.root, 'config', 'optionsful.yml')))
              envs = YAML::load_file(File.join(Rails.root, 'config', 'optionsful.yml')).symbolize_keys
              @config = envs[get_env].symbolize_keys
            end
          rescue
          end
        end
        @config = DEFAULT if @config.nil?
        @config
      end

      def get_env
        if defined? Rails
          env = :test if Rails.env.test?
          env = :development if Rails.env.development?
          env = :production if Rails.env.production?
        else
          env = :development
        end
        env
      end

      def load_from_file(file, environment)
        config = nil
        require 'yaml'
        if File.exist?(file)
          begin
            envs = YAML::load_file(file).symbolize_keys
            config = envs[environment].symbolize_keys
          rescue => e
            puts e.backtrace
          end
        end
        config
      end

      def method_missing(name, *args)
        return @config[name.to_sym] 
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
optionsful-0.3.2 lib/baurets/optionsful/config.rb
optionsful-0.3.1 lib/baurets/optionsful/config.rb
optionsful-0.3.0 lib/baurets/optionsful/config.rb