Module: Aerosol::AWS

Extended by:
AWS
Included in:
AWS
Defined in:
lib/aerosol/aws.rb

Overview

This module holds the connections for all AWS services used by the gem.

Instance Method Summary collapse

Instance Method Details

#credsObject



40
41
42
# File 'lib/aerosol/aws.rb', line 40

def creds
  Hash[env_attrs.map { |attr| [attr, public_send(attr)] }].reject { |k, v| v.nil? }
end

#env_attr(*names) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/aerosol/aws.rb', line 21

def env_attr(*names)
  names.each do |name|
    define_method name do
      instance_variable_get(:"@#{name}") || ENV[name.to_s.upcase]
    end

    define_method :"#{name}=" do |val|
      reset_cache!
      instance_variable_set(:"@#{name}", val)
    end

    env_attrs << name
  end
end

#env_attrsObject



36
37
38
# File 'lib/aerosol/aws.rb', line 36

def env_attrs
  @env_attrs ||= []
end

#reset_cache!Object



44
45
46
# File 'lib/aerosol/aws.rb', line 44

def reset_cache!
  services.each { |service| instance_variable_set(:"@#{service}", nil) }
end

#service(name, klass) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/aerosol/aws.rb', line 5

def service(name, klass)
  define_method name do
    if val = instance_variable_get(:"@#{name}")
      val
    else
      instance = klass.new(creds)
      instance_variable_set(:"@#{name}", instance)
    end
  end
  services << name
end

#servicesObject



17
18
19
# File 'lib/aerosol/aws.rb', line 17

def services
  @services ||= []
end