class Biosphere::Settings

Attributes

feature_manifests[RW]
path[RW]
settings[RW]

Public Class Methods

add_feature_manifest(feature, manifests=nil) click to toggle source
# File lib/biosphere/settings.rb, line 46
def add_feature_manifest(feature, manifests=nil)
    if manifests
        if !manifests.is_a?(Array)
            manifests = [manifests]
        end

        c = @feature_manifests_hash ||= ::Hash.new
        c = DeepDup.deep_dup(c)
        a = (c[feature] ||= ::Array.new)
        c[feature] = (a + manifests).uniq
        @feature_manifests_hash = c
    end

    return feature_manifests(feature)
end
class_attribute(*attrs) click to toggle source
# File lib/biosphere/settings.rb, line 9
def class_attribute(*attrs)
    singleton_class.class_eval do
        attr_accessor(*attrs)
    end

    class_attributes.merge(attrs)
end
class_attributes() click to toggle source
# File lib/biosphere/settings.rb, line 17
def class_attributes
    @class_attributes ||= ::Set.new
end
feature_manifests(feature=nil) click to toggle source
# File lib/biosphere/settings.rb, line 66
def feature_manifests(feature=nil)
    if feature
        if @feature_manifests_hash
            return @feature_manifests_hash[feature]
        else
            return nil
        end
    else
        return @feature_manifests_hash
    end
end
find_files(p) click to toggle source

Finds files from relative path

# File lib/biosphere/settings.rb, line 83
def find_files(p)
    if !$current_biosphere_path_stack
        $current_biosphere_path_stack = "."
    end
    relative_path = $current_biosphere_path_stack + "/" + p
    entries = Dir[(relative_path)] - [".", ".."]
    return entries
end
inherited(subclass) click to toggle source
# File lib/biosphere/settings.rb, line 21
def inherited(subclass)
    class_attributes.each do |attr|
        value = send(attr)
        value = DeepDup.deep_dup(value) # rescue value
        subclass.class_attribute attr
        subclass.send("#{attr}=", value)

        p = path
        if p != ""
            p = p + "/"
        end
        subclass.send("path=", p + subclass.name.split('::').last)
    end
end
new(settings = {}) click to toggle source
# File lib/biosphere/settings.rb, line 99
def initialize(settings = {})
    @settings = DeepDup.deep_dup(self.class.settings_hash)
    @feature_manifests = DeepDup.deep_dup(self.class.feature_manifests_hash)
    @path = self.class.path
    if settings
        @settings.deep_merge!(settings)
    end
end
path() click to toggle source
# File lib/biosphere/settings.rb, line 78
def path()
    return @path
end
set_feature_manifests(obj) click to toggle source
# File lib/biosphere/settings.rb, line 62
def set_feature_manifests(obj)
    @feature_manifests_hash = obj
end
settings(settings=nil) click to toggle source
# File lib/biosphere/settings.rb, line 36
def settings(settings=nil)
    if settings
        c = @settings_hash ||= ::Hash.new
        c = DeepDup.deep_dup(c)
        c.deep_merge!(settings, {:overwrite_arrays => true})
        @settings_hash = c
    end
    return @settings_hash
end

Public Instance Methods

[](key) click to toggle source
# File lib/biosphere/settings.rb, line 108
def [](key)
    return @settings[key]
end