Sha256: 345d323ed2b6747a52040861ae99d9f9e2cb86282e9162f8137eceaf7b2bf19d

Contents?: true

Size: 1.15 KB

Versions: 15

Compression:

Stored size: 1.15 KB

Contents

# This module holds the connections for all AWS services used by the gem.
module Aerosol::AWS
  extend self

  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

  def services
    @services ||= []
  end

  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

  def env_attrs
    @env_attrs ||= []
  end

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

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

  service :sts, Aws::STS::Client
  service :s3, Aws::S3::Client
  service :compute, Aws::EC2::Client
  service :auto_scaling, Aws::AutoScaling::Client
  env_attr :credentials, :stub_responses
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
aerosol-1.10.0 lib/aerosol/aws.rb
aerosol-1.9.2 lib/aerosol/aws.rb
aerosol-1.9.1 lib/aerosol/aws.rb
aerosol-1.9.0 lib/aerosol/aws.rb
aerosol-1.8.0 lib/aerosol/aws.rb
aerosol-1.7.1 lib/aerosol/aws.rb
aerosol-1.7.0 lib/aerosol/aws.rb
aerosol-1.7.0.pre.1 lib/aerosol/aws.rb
aerosol-1.6.0 lib/aerosol/aws.rb
aerosol-1.5.1 lib/aerosol/aws.rb
aerosol-1.3.0 lib/aerosol/aws.rb
aerosol-1.2.0 lib/aerosol/aws.rb
aerosol-1.1.0 lib/aerosol/aws.rb
aerosol-1.0.2 lib/aerosol/aws.rb
aerosol-1.0.1 lib/aerosol/aws.rb