class Queuel::AWSConstantFinder

Constants

AWSSDKMissingError

Attributes

klass_name[R]

Public Class Methods

find(*args) click to toggle source
# File lib/queuel/aws_constant_finder.rb, line 8
def self.find(*args)
  new(*args).find
end
new(klass_name) click to toggle source
# File lib/queuel/aws_constant_finder.rb, line 14
def initialize(klass_name)
  @klass_name = klass_name.to_s.upcase
end

Public Instance Methods

find() click to toggle source
# File lib/queuel/aws_constant_finder.rb, line 18
def find
  return fetch_const if fetch_const

  logger.info "Loading AWS SDK..."
  fetch_sdk "aws-sdk" do
    return fetch_const if supported_version?
  end

  fetch_sdk 'aws-sdk-v1' do
    return fetch_const
  end

  fail!
end

Private Instance Methods

constants() click to toggle source
# File lib/queuel/aws_constant_finder.rb, line 40
def constants
  ["AWS", klass_name]
end
fail!() click to toggle source
# File lib/queuel/aws_constant_finder.rb, line 33
def fail!
  message = "Couldn't find any compatible aws-sdk gem, try installing aws-sdk-v1"
  logger.error message
  raise(AWSSDKMissingError, message)
end
fetch_const() click to toggle source
# File lib/queuel/aws_constant_finder.rb, line 45
def fetch_const
  constants.inject(Object) { |singleton, string|
    singleton.public_send(:const_get, string)
  }
rescue NameError, ArgumentError
  nil
end
fetch_sdk(gem_name) { || ... } click to toggle source
# File lib/queuel/aws_constant_finder.rb, line 54
def fetch_sdk(gem_name)
  require gem_name
  yield
rescue LoadError
  nil
end
supported_version?() click to toggle source
# File lib/queuel/aws_constant_finder.rb, line 62
def supported_version?
  ::AWS::VERSION.start_with?("1")
end