Sha256: 42bee7cbe3573e333f814b67b64312789b33d6da207af97c5552715e02277cb1
Contents?: true
Size: 1.29 KB
Versions: 33
Compression:
Stored size: 1.29 KB
Contents
require 'fog/aws' # This module holds the connections for all AWS services used by the gem. module Dockly::AWS extend self autoload :S3Writer, 'dockly/aws/s3_writer' 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 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 def reset_cache! services.each { |service| instance_variable_set(:"@#{service}", nil) } end service :s3, Fog::Storage::AWS env_attr :aws_access_key_id, :aws_secret_access_key end
Version data entries
33 entries across 33 versions & 1 rubygems