class S3Wrapper::Profile

Constants

CONFIG_FILE

Attributes

aws_access_key[RW]
aws_secret_key[RW]
bucket_name[RW]
host_name[RW]
name[RW]

Public Class Methods

config_default(params) click to toggle source
# File lib/s3-wrapper/profile.rb, line 8
def self.config_default(params)
  self::create('default', params)
end
create(name, params) click to toggle source
# File lib/s3-wrapper/profile.rb, line 12
def self.create(name, params)
  config = read_config(name, false)
  params.each do |key, value|
    config[name][key] = value
  end
  self::write_config(config)
  S3Wrapper::Profile.new(name, config[name])
end
delete(name) click to toggle source
# File lib/s3-wrapper/profile.rb, line 21
def self.delete(name)
  config = read_config(name, false)
  config.delete(name)
  self::write_config(config)
end
get(name) click to toggle source
# File lib/s3-wrapper/profile.rb, line 27
def self.get(name)
  config = read_config(name, true)
  S3Wrapper::Profile.new(name, config[name])
end
new(name, params = {}) click to toggle source
# File lib/s3-wrapper/profile.rb, line 32
def initialize(name, params = {})
  self.name = name
  params.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Private Class Methods

read_config(name, with_default) click to toggle source
# File lib/s3-wrapper/profile.rb, line 46
def self.read_config(name, with_default)
  config = {}
  begin
    config = File.open(ENV['HOME'] + '/' + CONFIG_FILE) { |f| YAML.load(f) }
  rescue

  end
  config = {} unless config
  config[name] = {} unless config[name]
  if with_default && config['default'] && name != 'default'
    config['default'].each do |key, value|
      config[name][key] = value unless config[name][key] && value;
    end
  end
  config
end
write_config(config) click to toggle source
# File lib/s3-wrapper/profile.rb, line 63
def self.write_config(config)
  open(ENV['HOME'] + '/' + CONFIG_FILE, 'w+') { |f| YAML.dump(config, f) }
end

Public Instance Methods

to_hash() click to toggle source
# File lib/s3-wrapper/profile.rb, line 39
def to_hash
  Hash[*instance_variables.map { |v|
    [v.to_sym, instance_variable_get(v)]
  }.flatten]
end