lib/chamber/file.rb
###
# Internal: Creates a settings file representing a path to a file on the
# filesystem.
#
# Optionally, namespaces may be passed in which will be passed to the Settings
# object for consideration of which data will be parsed (see the Settings
# object's documentation for details on how this works).
#
# Examples:
#
#   ###
#   # It can be created by passing namespaces
#   #
#   settings_file = Chamber::File.new path:       '/tmp/settings.yml',
#                                     namespaces: {
#                                       environment: ENV['RAILS_ENV'] }
#   # => <Chamber::File>
#
#   settings_file.to_settings
#   # => <Chamber::Settings>
#
#   ###
#   # It can also be created without passing any namespaces
#   #
#   Chamber::File.new path: '/tmp/settings.yml'
#   # => <Chamber::File>
#
Creates a settings file representing a path to a file on the
filesystem.

Optionally, namespaces may be passed in which will be passed to the Settings
object for consideration of which data will be parsed (see the Settings
object's documentation for details on how this works).



It can be created by passing namespaces





It can also be created without passing any namespaces


Creates a settings file representing a path to a file on the filesystem . Optionally namespaces may be passed in which will be passed to the Settings object for consideration of which data will be parsed ( see the Settings object ' s documentation for details on how this works ) . It can be created by passing namespaces It can also be created without passing any namespaces
def secure
    insecure_settings = to_settings.insecure.to_flattened_name_hash
    secure_settings   = to_settings.insecure.secure.to_flattened_name_hash
    file_contents     = read
    insecure_settings.each_pair do |name_pieces, value|
      secure_value  = secure_settings[name_pieces]
      escaped_name  = Regexp.escape(name_pieces.last)
      escaped_value = Regexp.escape(value)
      file_contents.
        sub!(
          /^(\s*)_secure_#{escaped_name}(\s*):(\s*)['"]?#{escaped_value}['"]?$/,
          "\\1_secure_#{name_pieces.last}\\2:\\3#{secure_value}")
    end
    write(file_contents)
  end
def secure insecure_settings = to_settings . insecure . to_flattened_name_hash secure_settings = to_settings . insecure . secure . to_flattened_name_hash file_contents = read insecure_settings . each_pair do | name_pieces , value | secure_value = secure_settings [ name_pieces ] escaped_name = Regexp . escape ( name_pieces . last ) escaped_value = Regexp . escape ( value ) file_contents . sub! ( / ^( \s *)_secure_ #{ escaped_name } ( \s *):( \s *)['"]? #{ escaped_value } ['"]?$ / , "\\1_secure_#{name_pieces.last}\\2:\\3#{secure_value}" ) end write ( file_contents ) end
Internal: Creates a settings file representing a path to a file on the
filesystem.
Internal : Creates a settings file representing a path to a file on the filesystem .