class Humidifier::Config::Mapping

Attributes

clazz[R]
mapper[R]

Public Class Methods

new(opts = {}, &block) click to toggle source
# File lib/humidifier/config/mapping.rb, line 8
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/config/mapping.rb, line 19
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/config/mapping.rb, line 25
def mapper_from(opts, &block)
  if opts[:using]
    opts[:using].new
  elsif block_given?
    Class.new(Mapper, &block).new
  else
    Mapper.new
  end
end
normalized(name) click to toggle source
# File lib/humidifier/config/mapping.rb, line 35
def normalized(name)
  name.start_with?('AWS') ? name : "AWS::#{name}"
end