class Humidifier::Reservoir::Mapping

Contains the configuration for a mapping between a YAML file name and an AWS resource. May optionally contain a Mapper (uses the BaseMapper) by default.

Attributes

clazz[R]
mapper[R]

Public Class Methods

new(opts = {}, &block) click to toggle source
# File lib/humidifier/reservoir/mapping.rb, line 9
def initialize(opts = {}, &block)
  @clazz = Humidifier[normalized(opts[:to])]
  raise Error, "Invalid resource: #{opts[:to].inspect}" if @clazz.nil?

  if opts[:using] && block_given?
    raise Error, 'Cannot specify :using and provide an anonymous mapper'
  end

  @mapper = mapper_from(opts, &block)
end

Public Instance Methods

resource_for(name, attributes) click to toggle source
# File lib/humidifier/reservoir/mapping.rb, line 20
def resource_for(name, attributes)
  mapper.resource_for(clazz, name, attributes)
end

Private Instance Methods

mapper_from(opts, &block) click to toggle source
# File lib/humidifier/reservoir/mapping.rb, line 26
def mapper_from(opts, &block)
  if opts[:using]
    opts[:using].new
  elsif block_given?
    Class.new(BaseMapper, &block).new
  else
    BaseMapper.new
  end
end
normalized(to) click to toggle source
# File lib/humidifier/reservoir/mapping.rb, line 36
def normalized(to)
  to.start_with?('AWS') ? to : "AWS::#{to}"
end