Class: Ant::Server::Nanoservice::Factory

Inherits:
Object
  • Object
show all
Includes:
DRY::ResourceInjector
Defined in:
lib/ant/server/nanoservice/factory.rb

Instance Method Summary collapse

Methods included from DRY::ResourceInjector

#register, #resource, #resources

Constructor Details

#initialize(model) ⇒ Factory

Returns a new instance of Factory.



7
8
9
# File 'lib/ant/server/nanoservice/factory.rb', line 7

def initialize(model)
  @model = model
end

Instance Method Details

#create(data, source = resource(:default)) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/ant/server/nanoservice/factory.rb', line 11

def create(data, source = resource(:default))
  repository = resource(source)
  model = @model.new(data)
  model.repository = repository
  model.create
  model
end

#get(id, source = resource(:default)) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/ant/server/nanoservice/factory.rb', line 19

def get(id, source = resource(:default))
  repository = resource(source)
  data = repository.get(id)
  model = @model.new(data)
  model.repository = repository
  model
end