Class: Fabrique::BeanDefinitionRegistry

Inherits:
Object
  • Object
show all
Includes:
TSort
Defined in:
lib/fabrique/bean_definition_registry.rb

Instance Method Summary collapse

Constructor Details

#initialize(definitions) ⇒ BeanDefinitionRegistry

Returns a new instance of BeanDefinitionRegistry.



11
12
13
# File 'lib/fabrique/bean_definition_registry.rb', line 11

def initialize(definitions)
  @defs = definitions.map { |d| d.is_a?(BeanDefinition) ? d : BeanDefinition.new(d) }
end

Instance Method Details

#get_definition(bean_name) ⇒ Object



15
16
17
# File 'lib/fabrique/bean_definition_registry.rb', line 15

def get_definition(bean_name)
  @defs.detect { |d| d.id == bean_name } or raise MissingBeanError.new("missing bean #{bean_name.inspect}")
end

#get_definitionsObject



19
20
21
# File 'lib/fabrique/bean_definition_registry.rb', line 19

def get_definitions
  @defs
end

#get_gem_definitionsObject



23
24
25
# File 'lib/fabrique/bean_definition_registry.rb', line 23

def get_gem_definitions
  @defs.collect(&:gem).compact
end

#validate!Object



27
28
29
30
31
# File 'lib/fabrique/bean_definition_registry.rb', line 27

def validate!
  tsort
rescue TSort::Cyclic => e
  raise CyclicBeanDependencyError.new(e.message.gsub(/topological sort failed/, "cyclic bean dependency error"))
end