Class: Husky::Repo::InMemory

Inherits:
Object
  • Object
show all
Defined in:
lib/husky/repo.rb

Instance Method Summary collapse

Constructor Details

#initializeInMemory

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

#allObject



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