Sha256: 27ca14f00ccf77a336531efe1137a6c86f2c0274cbd7be18d5a750da1764d8c2

Contents?: true

Size: 893 Bytes

Versions: 80

Compression:

Stored size: 893 Bytes

Contents

module Daddy
  module Utils
    
    class Config
      
      def initialize(yaml_path_or_hash = nil)
        if yaml_path_or_hash.is_a?(Hash)
          @hash = yaml_path_or_hash
        elsif yaml_path_or_hash and File.exist?(yaml_path_or_hash)
          @hash = YAML.load_file(yaml_path_or_hash)
        else
          @hash = {}
        end
      end
    
      def [](key)
        ret = false
    
        if key.to_s.end_with?('?')
          ret = @hash[key.to_s[0..-2]] ? true : false
        else
          ret = @hash[key.to_s]
    
          if ret.nil?
            ret = self.class.new
          elsif ret.is_a?(Hash)
            ret = self.class.new(ret)
          end
        end
    
        ret
      end
      
      def []=(key, value)
        @hash[key.to_s] = value
      end
      
      def method_missing(name, *args)
        self[name]
      end
    
    end

  end
end

Version data entries

80 entries across 80 versions & 1 rubygems

Version Path
daddy-0.7.3 lib/daddy/utils/config.rb
daddy-0.7.2 lib/daddy/utils/config.rb
daddy-0.7.1 lib/daddy/utils/config.rb
daddy-0.7.0 lib/daddy/utils/config.rb
daddy-0.6.6 lib/daddy/utils/config.rb
daddy-0.6.5 lib/daddy/utils/config.rb
daddy-0.6.4 lib/daddy/utils/config.rb
daddy-0.6.3 lib/daddy/utils/config.rb
daddy-0.6.2 lib/daddy/utils/config.rb
daddy-0.6.1 lib/daddy/utils/config.rb
daddy-0.6.0 lib/daddy/utils/config.rb
daddy-0.5.34 lib/daddy/utils/config.rb
daddy-0.5.33 lib/daddy/utils/config.rb
daddy-0.5.32 lib/daddy/utils/config.rb
daddy-0.5.31 lib/daddy/utils/config.rb
daddy-0.5.30 lib/daddy/utils/config.rb
daddy-0.5.29 lib/daddy/utils/config.rb
daddy-0.5.28 lib/daddy/utils/config.rb
daddy-0.5.27 lib/daddy/utils/config.rb
daddy-0.5.26 lib/daddy/utils/config.rb