poro_repository 0.0.2 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/poro_repository.rb +14 -0
- data/poro_repository.gemspec +1 -1
- data/spec/poro_repository_spec.rb +37 -3
- metadata +2 -2
data/lib/poro_repository.rb
CHANGED
@@ -65,6 +65,13 @@ class PoroRepository
|
|
65
65
|
id
|
66
66
|
end
|
67
67
|
|
68
|
+
def delete_record record
|
69
|
+
id = id_from_record(record)
|
70
|
+
path = record_path(type_from_record(record), id)
|
71
|
+
FileUtils.rm path
|
72
|
+
forget_record record if @remember
|
73
|
+
end
|
74
|
+
|
68
75
|
def load_all type
|
69
76
|
all_ids_for_type(type).collect do |id|
|
70
77
|
load_record type, id
|
@@ -155,6 +162,13 @@ class PoroRepository
|
|
155
162
|
@instantiated_records[type][id_from_record(record)] = record
|
156
163
|
end
|
157
164
|
|
165
|
+
def forget_record record
|
166
|
+
type = type_from_record(record)
|
167
|
+
if @instantiated_records[type].is_a?(WeakHash)
|
168
|
+
@instantiated_records[type].delete(id_from_record(record))
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
158
172
|
def previous_instantiated type, id
|
159
173
|
records = @instantiated_records[type] || {}
|
160
174
|
ref = records[id]
|
data/poro_repository.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "poro_repository"
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.1.2"
|
7
7
|
s.authors = ["Joel Plane"]
|
8
8
|
s.email = ["joel.plane@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/joelplane/poro_repository"
|
@@ -4,7 +4,7 @@ require 'ostruct'
|
|
4
4
|
describe PoroRepository do
|
5
5
|
|
6
6
|
subject do
|
7
|
-
PoroRepository.new("/tmp/test-
|
7
|
+
PoroRepository.new("/tmp/test-poro-repository").tap do |repo|
|
8
8
|
# disable storing of records in memory, so we know we're not cheating
|
9
9
|
repo.remember = false
|
10
10
|
end
|
@@ -64,7 +64,7 @@ describe PoroRepository do
|
|
64
64
|
describe "boundaries" do
|
65
65
|
|
66
66
|
subject do
|
67
|
-
PoroRepository.new("/tmp/test-
|
67
|
+
PoroRepository.new("/tmp/test-poro-repository").tap do |repo|
|
68
68
|
repo.boundary :Invoice, :@contact
|
69
69
|
repo.remember = false
|
70
70
|
end
|
@@ -123,7 +123,7 @@ describe PoroRepository do
|
|
123
123
|
describe "object lifecycle" do
|
124
124
|
|
125
125
|
subject do
|
126
|
-
PoroRepository.new("/tmp/test-
|
126
|
+
PoroRepository.new("/tmp/test-poro-repository")
|
127
127
|
end
|
128
128
|
|
129
129
|
let(:invoice) do
|
@@ -191,4 +191,38 @@ describe PoroRepository do
|
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|
194
|
+
describe "#delete_record" do
|
195
|
+
|
196
|
+
subject do
|
197
|
+
PoroRepository.new("/tmp/test-poro-repository").tap do |repo|
|
198
|
+
repo.boundary :Invoice, :@contact
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
let(:contact) do
|
203
|
+
TestObject.new.tap do |o|
|
204
|
+
o.id = '234'
|
205
|
+
o.type = 'Contact'
|
206
|
+
o.name = 'John Smith'
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
let(:invoice) do
|
211
|
+
TestObject.new.tap do |o|
|
212
|
+
o.id = '345'
|
213
|
+
o.type = 'Invoice'
|
214
|
+
o.contact = contact
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
it "deletes the record, and not beyond boundary" do
|
219
|
+
record_id = subject.save_record invoice
|
220
|
+
subject.load_record('Invoice', record_id).should == invoice
|
221
|
+
subject.delete_record(invoice)
|
222
|
+
subject.load_record('Invoice', record_id).should be_nil
|
223
|
+
subject.load_all('Contact').first.name.should == 'John Smith'
|
224
|
+
end
|
225
|
+
|
226
|
+
end
|
227
|
+
|
194
228
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poro_repository
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|