Configurability::Config::

DataUtilities

module

A collection of data-structure-manipulation functions.

Public Instance Methods

anchor
stringify_keys( hash )

Return a version of the given hash with its keys transformed into Strings from whatever they were before.

# File lib/configurability/config.rb, line 343
def stringify_keys( hash )
        newhash = {}
        hash.each do |key,val|
                if val.is_a?( Hash )
                        newhash[ key.to_s ] = stringify_keys( val )
                else
                        newhash[ key.to_s ] = val
                end
        end

        return newhash
end
anchor
symbolify_keys( hash )

Return a duplicate of the given hash with its identifier-like keys transformed into symbols from whatever they were before.

# File lib/configurability/config.rb, line 325
def symbolify_keys( hash )
        newhash = {}
        hash.each do |key,val|
                key = key.to_sym if key.respond_to?( :to_sym )

                if val.is_a?( Hash )
                        newhash[ key ] = symbolify_keys( val )
                else
                        newhash[ key ] = val
                end
        end

        return newhash
end
anchor
untaint_hash( hash )

Return a copy of the specified hash with all of its values untainted.

# File lib/configurability/config.rb, line 292
def untaint_hash( hash )
        newhash = {}
        hash.each_key do |key|
                newhash[ key ] = untaint_value( hash[key] )
        end
        return newhash
end
anchor
untaint_value( val )

Return an untainted copy of the specified val.

# File lib/configurability/config.rb, line 302
def untaint_value( val )
        case val
        when Hash
                return untaint_hash( val )

        when Array
                return val.collect {|v| untaint_value(v) }

        when NilClass, TrueClass, FalseClass, Numeric, Symbol, Encoding
                return val

        else
                if val.respond_to?( :dup ) && val.respond_to?( :untaint )
                        return val.dup.untaint
                else
                        return val
                end
        end
end