Class: Kybus::Storage::Factory
- Inherits:
-
Object
- Object
- Kybus::Storage::Factory
- Includes:
- DRY::ResourceInjector
- Defined in:
- lib/kybus/storage/factory.rb
Overview
charge of sending objects into storage and fetching also from them.
Instance Method Summary collapse
- #create(data, source = resource(:default)) ⇒ Object
- #get(id, source = resource(:default)) ⇒ Object
-
#initialize(model) ⇒ Factory
constructor
A new instance of Factory.
Constructor Details
#initialize(model) ⇒ Factory
Returns a new instance of Factory.
9 10 11 |
# File 'lib/kybus/storage/factory.rb', line 9 def initialize(model) @model = model end |
Instance Method Details
#create(data, source = resource(:default)) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/kybus/storage/factory.rb', line 13 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
21 22 23 24 25 26 27 |
# File 'lib/kybus/storage/factory.rb', line 21 def get(id, source = resource(:default)) repository = resource(source) data = repository.get(id) model = @model.new(data) model.repository = repository model end |