Module: DomainDriven::Service::Repo

Defined in:
lib/domain_driven/service.rb

Overview

this is the Repository Factory

Class Attribute Summary collapse

Class Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object (private)



45
46
47
48
49
50
51
# File 'lib/domain_driven/service.rb', line 45

def method_missing(name,*args)
  if name.to_s[0...4] == 'for_'
    self.for(name.to_s[4..-1].to_sym)
  else
    super
  end
end

Class Attribute Details

.factoryObject



28
29
30
31
# File 'lib/domain_driven/service.rb', line 28

def factory
  return @factory if @factory
  raise "Repo has no factory initialized.  Add an intializer file with something like this: DomainDriven::Service::Repo.factory = { course:  CourseRepository, ...}" 
end

.loggerObject



24
25
26
# File 'lib/domain_driven/service.rb', line 24

def logger 
  @logger ||= Logger.new(STDOUT)
end

Class Method Details

.for(name) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/domain_driven/service.rb', line 33

def for(name) 
  logger.info("Provisioning Repo #{name}")
  if repo_class_name = factory[name]
    repo_class = repo_class_name.to_s.classify.constantize 
    repo = repo_class.new(name) 
    repo
  else
    raise "repository not found: (#{name})"
  end
end

.method_missing(name, *args) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/domain_driven/service.rb', line 45

def method_missing(name,*args)
  if name.to_s[0...4] == 'for_'
    self.for(name.to_s[4..-1].to_sym)
  else
    super
  end
end