Module: Boxlet::Config

Included in:
Boxlet
Defined in:
lib/boxlet/config.rb

Constant Summary collapse

ARGS =
{
  :environment => {
    :short      => 'E',
    :default    => 'development'
  },
  :path => {
    :short      => 'f',
    :default    => Proc.new { Dir.pwd }
  },
  :port => {
    :short      => 'p',
    :default    => 8077,
    :sanitizer  => Proc.new { |p| p.to_i }
  },
  :host => {
    :short      => 'o',
    :default    => 'localhost'
  },
  :server_type => {
    :short      => 's',
    :default    => 'rack',
    :sanitizer  => Proc.new { |p| p.to_sym }
  },
  :daemonize => {
    :short      => 'd',
    :default    => 'false',
    :sanitizer  => Proc.new { |p| p == true || p == 'true' }
  },
  :debug => {
    :short      => 'D',
    :default    => 'true',
    :sanitizer  => Proc.new { |p| p == true ||  p == 'true' }
  },
  :upload_dir => {
    :short      => 'U',
    :default    => './uploads'
  },
  :tmp_dir => {
    :short      => 'T',
    :default    => './tmp'
  },
  :file_system_root => {
    :short      => 'r',
    :default    => '/'
  },
  :capacity => {
    :short      => 'C',
    :default    => '90%',
    :sanitizer  => Proc.new { |p| (p.to_i.to_s == p) ? p.to_i : p }
  },
  :pid_file => {
    :short      => 'P',
    :default    => Proc.new { Dir.pwd + "/server.pid" }
  },
  :log_file => {
    :short      => 'L',
    :default    => Proc.new { Dir.pwd + "/server.log" }
  },
  :s3 => {
    :default    => { enabled: false }
  }
}

Instance Method Summary collapse

Instance Method Details

#populate_params!(argv, path_to_config) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/boxlet/config.rb', line 67

def populate_params!(argv, path_to_config)
  @raw_config = load_config_file(path_to_config)
  @raw_params = parse_arguments(argv)

  @config = @raw_params
  @config[:debug] = @raw_config[:debug] || @raw_params[:debug]
end

#symbolize_keys(hash) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/boxlet/config.rb', line 75

def symbolize_keys(hash)
  hash.inject({}){|result, (key, value)|
    new_key = key.instance_of?(String) ? key.to_sym : key
    new_value = value.instance_of?(Hash) ? symbolize_keys(value) : value

    result[new_key] = new_value
    result
  }
end