Module: Dockly::AWS

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

Overview

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

Instance Method Summary collapse

Instance Method Details

#credsObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dockly/aws.rb', line 42

def creds
  attrs = Hash[env_attrs.map { |attr| [attr, public_send(attr)] }].reject { |k, v| v.nil? }
  if attrs.empty?
    if ENV['FOG_CREDENTIAL']
      attrs = {} # let Fog use the env var
    else
      attrs = { :use_iam_profile => true }
    end
  end
  attrs
end

#env_attr(*names) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dockly/aws.rb', line 23

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



38
39
40
# File 'lib/dockly/aws.rb', line 38

def env_attrs
  @env_attrs ||= []
end

#reset_cache!Object



54
55
56
# File 'lib/dockly/aws.rb', line 54

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

#service(name, klass) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dockly/aws.rb', line 7

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



19
20
21
# File 'lib/dockly/aws.rb', line 19

def services
  @services ||= []
end