class RbRotate::Configuration

General configuration file.

Public Class Methods

each_directory(&block) click to toggle source

Traverses through each directory configuration. (Shortcut for instace call.)

# File lib/rb.rotate/configuration.rb, line 136
def self.each_directory(&block)
    self::get.each_directory(&block)
end
find_path(path) click to toggle source

Alias for find_path.

# File lib/rb.rotate/configuration.rb, line 144
def self.find_path(path)
    self::get.find_path(path)
end
get() click to toggle source

Returns the single instance.

# File lib/rb.rotate/configuration.rb, line 124
def self.get
    if @@self.nil?
        @@self = self::new
    end
    
    return @@self
end
read(file) click to toggle source

Opens the file. (Shortcut for instance call.)

# File lib/rb.rotate/configuration.rb, line 116
def self.read(file)
    self::get.read(file)
end

Public Instance Methods

[](name) click to toggle source

Returns an item.

# File lib/rb.rotate/configuration.rb, line 190
def [](name)
    @data[name]
end
each_directory() { |new(name, dir)| ... } click to toggle source

Traverses through each directory configuration.

# File lib/rb.rotate/configuration.rb, line 206
def each_directory
    @data[:dirs].each_pair do |name, dir|
        yield Directory::new(name, dir)
    end
end
find_path(path) click to toggle source

Looks for directory in configuration.

# File lib/rb.rotate/configuration.rb, line 216
def find_path(path)
    @data.each_pair do |name, dir|
        if dir[:directory] == path
            return Directory::new(name, dir)
        end
    end
    
    return nil
end
method_missing(name) click to toggle source

Handles method calls.

# File lib/rb.rotate/configuration.rb, line 198
def method_missing(name)
    self[name]
end
read(file) click to toggle source

Opens the file.

# File lib/rb.rotate/configuration.rb, line 152
def read(file)
    data = YAML.load(::File.read(file))
    @data = { }
    
    # Converts strings to symbols
    data.each_pair do |name, section|
        section_data = { }
        @data[name.to_sym]= section_data
        
        if section.kind_of? Hash
            section.each_pair do |key, value|
                section_data[key.to_sym] = value
            end
        end
    end
    
    defaults = YAML.load(::File.read(@data[:paths][:"defaults file"]))
    
    # Merges with defaults
    defaults.each_pair do |name, section|
        name = name.to_sym
        if not @data.has_key? name
            @data[name] = value
        elsif section.kind_of? Hash
            section.each_pair do |key, value|
                key = key.to_sym
                if not @data[name].has_key? key
                    @data[name][key] = value
                end
            end
        end
    end
end