Class: Husky::Repo::InMemory
- Inherits:
-
Object
- Object
- Husky::Repo::InMemory
- Defined in:
- lib/husky/repo.rb
Instance Method Summary collapse
- #all ⇒ Object
- #create(attributes = {}) ⇒ Object
- #destroy(object) ⇒ Object
- #find(id) ⇒ Object
-
#initialize ⇒ InMemory
constructor
A new instance of InMemory.
- #new(attributes = {}) ⇒ Object
- #save(object) ⇒ Object
- #update(item, attributes) ⇒ Object
Constructor Details
#initialize ⇒ InMemory
Returns a new instance of InMemory.
54 55 56 57 |
# File 'lib/husky/repo.rb', line 54 def initialize @records = {} @id = 1 end |
Instance Method Details
#all ⇒ Object
59 60 61 |
# File 'lib/husky/repo.rb', line 59 def all @records end |
#create(attributes = {}) ⇒ Object
78 79 80 |
# File 'lib/husky/repo.rb', line 78 def create(attributes = {}) save(new(attributes)) end |
#destroy(object) ⇒ Object
86 87 88 |
# File 'lib/husky/repo.rb', line 86 def destroy(object) @records.delete(object.id) end |
#find(id) ⇒ Object
67 68 69 |
# File 'lib/husky/repo.rb', line 67 def find(id) entity.new(@records[id.to_i]) end |
#new(attributes = {}) ⇒ Object
63 64 65 |
# File 'lib/husky/repo.rb', line 63 def new(attributes = {}) entity.new(data_source.new(attributes)) end |
#save(object) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/husky/repo.rb', line 71 def save(object) object.id = @id @records[@id] = object @id += 1 entity.new(object) end |
#update(item, attributes) ⇒ Object
82 83 84 |
# File 'lib/husky/repo.rb', line 82 def update(item, attributes) entity.new(item.update_attributes(attributes)) end |