Class: Rddd::Repositories::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/rddd/aggregates/repositories/factory.rb

Overview

Create instance of Repository using the Configration#repository_creator and passing the class along.

Constant Summary collapse

CreatorNotGiven =
Class.new(RuntimeError)

Class Method Summary collapse

Class Method Details

.build(clazz) ⇒ Object

Raises:



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rddd/aggregates/repositories/factory.rb', line 18

def self.build(clazz)
  creator = Configuration.instance.repository_creator

  raise CreatorNotGiven unless creator

  begin
    repository = creator.call(clazz)
  rescue
    raise NotExistingRepository unless repository
  end

  repository.new
end