class CrossPost::Config::SubConfig

Public Class Methods

new(config = {}) click to toggle source
# File lib/cross-post/config.rb, line 10
def initialize(config = {})
        @config = config
end

Public Instance Methods

[](key) click to toggle source
# File lib/cross-post/config.rb, line 18
def [](key)
        case key
        when String
                current = @config
                key.split(/\./).each do |k|
                        current = current[k]
                        return nil if current.nil?
                end
                current
        else
                @config[key]
        end
end
[]=(key, value) click to toggle source
# File lib/cross-post/config.rb, line 36
def []=(key, value)
        case key
        when String
                *key, last = key.to_s.split(/\./)
                current    = @config
                key.each do |k|
                        next_ = current[k]
                        case next_
                        when nil
                                next_ = current[k] = {}
                        when Hash
                        else
                                raise "Invalid entry, Hash expected, had #{next_.class} (#{next_})"
                        end
                        current = next_
                end
                current[last] = value
        else
                @config[key] = value
        end
end
each(&block) click to toggle source
# File lib/cross-post/config.rb, line 14
def each(&block)
        @config.each &block
end
fetch(key, default = nil) click to toggle source
# File lib/cross-post/config.rb, line 32
def fetch(key, default = nil)
        self[key] || default
end