Class: Humidifier::Config::Mapping

Inherits:
Object
  • Object
show all
Defined in:
lib/humidifier/config/mapping.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}, &block) ⇒ Mapping

Returns a new instance of Mapping.

Raises:



8
9
10
11
12
13
14
15
16
17
# 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

Instance Attribute Details

#clazzObject (readonly)

Returns the value of attribute clazz.



6
7
8
# File 'lib/humidifier/config/mapping.rb', line 6

def clazz
  @clazz
end

#mapperObject (readonly)

Returns the value of attribute mapper.



6
7
8
# File 'lib/humidifier/config/mapping.rb', line 6

def mapper
  @mapper
end

Instance Method Details

#resource_for(name, attributes) ⇒ Object



19
20
21
# File 'lib/humidifier/config/mapping.rb', line 19

def resource_for(name, attributes)
  mapper.resource_for(clazz, name, attributes)
end