Class: ToFactory::KlassInference

Inherits:
Object
  • Object
show all
Defined in:
lib/to_factory/klass_inference.rb

Instance Method Summary collapse

Constructor Details

#initialize(representations) ⇒ KlassInference

Returns a new instance of KlassInference.



9
10
11
12
13
14
15
# File 'lib/to_factory/klass_inference.rb', line 9

def initialize(representations)
  @mapping = {}

  representations.each do |r|
    set_mapping_from(r)
  end
end

Instance Method Details

#infer(factory_name, count = 0) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/to_factory/klass_inference.rb', line 17

def infer(factory_name, count=0)
  count = count + 1
  result  = @mapping[factory_name]
  return [result, count] if result.is_a? Class

  if result.nil?
    raise CannotInferClass.new(factory_name)
  end

  infer(result, count)
end