poro_repository 0.0.1 → 0.0.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/README.md CHANGED
@@ -31,7 +31,7 @@ Storing different entities separately
31
31
 
32
32
  ```ruby
33
33
  class Contact
34
- attr_accessor :id, :name
34
+ attr_accessor :id, :name, :company
35
35
  end
36
36
 
37
37
  class Company
@@ -62,12 +62,18 @@ loaded_contact.company == loaded_company #=> true
62
62
  loaded_contact.company.equal?(loaded_company) #=> true ; same object
63
63
  ```
64
64
 
65
- Caveats
65
+ Loading all records (it's all or nothing at the moment - no filtering)
66
+
67
+ ```ruby
68
+ repo = PoroRepository.new("/repository/path")
69
+ repo.load_all('Contact') #=> Array<Contact>
70
+ ```
71
+
72
+ Limitations
66
73
  -------
67
74
 
68
75
  * No consideration has been given to concurrency. If you need concurrency, you
69
- should probably use something else.
70
- * At least at this stage, it is only really suitable for storing hundreds of
71
- objects, not thousands or millions.
72
- * It's still very incomplete and is missing most features required for it to
73
- be generally useful.
76
+ could implement a mutex around repo access in your app, but you should
77
+ probably just use something else.
78
+ * There is currently no way to efficiently search for records - you must load
79
+ up all records of a particular type, and filter them in the application.
@@ -17,7 +17,7 @@ class PoroRepository::WeakHash < Hash
17
17
 
18
18
  def [] key
19
19
  ref = super(key)
20
- self.delete(key) if !ref.weakref_alive?
20
+ self.delete(key) if ref && !ref.weakref_alive?
21
21
  ref
22
22
  end
23
23
 
@@ -65,6 +65,12 @@ class PoroRepository
65
65
  id
66
66
  end
67
67
 
68
+ def load_all type
69
+ all_ids_for_type(type).collect do |id|
70
+ load_record type, id
71
+ end
72
+ end
73
+
68
74
  private
69
75
 
70
76
  def open_for_write path, &block
@@ -162,4 +168,11 @@ class PoroRepository
162
168
  end.flatten.compact
163
169
  end
164
170
 
171
+ def all_ids_for_type type
172
+ glob = record_path type, '*'
173
+ Dir[glob].collect do |path|
174
+ path.split('/').last # id
175
+ end
176
+ end
177
+
165
178
  end
@@ -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.0.1"
6
+ s.version = "0.0.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"
@@ -164,4 +164,31 @@ describe PoroRepository do
164
164
 
165
165
  end
166
166
 
167
+ describe "#load_all" do
168
+
169
+ let(:object1) do
170
+ TestObject.new.tap do |o|
171
+ o.type = 'RecordType'
172
+ o.some_field = 42
173
+ end
174
+ end
175
+
176
+ let(:object2) do
177
+ TestObject.new.tap do |o|
178
+ o.type = 'RecordType'
179
+ o.some_field = 43
180
+ end
181
+ end
182
+
183
+ specify do
184
+ object_id1 = subject.save_record object1
185
+ object_id2 = subject.save_record object2
186
+ all_records = subject.load_all('RecordType').sort_by(&:some_field)
187
+ all_records.collect(&:some_field).should == [42, 43]
188
+ all_records.collect do |r|
189
+ subject.send(:id_from_record, r)
190
+ end.should == [object_id1, object_id2]
191
+ end
192
+ end
193
+
167
194
  end
data/spec/test_object.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class TestObject
2
- attr_accessor :id, :type, :name, :terms, :contact, :due_days
2
+ attr_accessor :id, :type, :name, :terms, :contact, :due_days, :some_field
3
3
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'ostruct'
3
+
4
+ describe PoroRepository::WeakHash do
5
+
6
+ subject do
7
+ PoroRepository::WeakHash.new.tap do |h|
8
+ h[:key1] = 'value1'
9
+ h[:key2] = 'value2'
10
+ end
11
+ end
12
+
13
+ describe do
14
+ specify "accessing non-existent key returns nil" do
15
+ subject[:non_existent_key].should be_nil
16
+ end
17
+ end
18
+
19
+ 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.0.1
4
+ version: 0.0.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-06 00:00:00.000000000 Z
12
+ date: 2013-10-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -45,6 +45,7 @@ files:
45
45
  - spec/poro_repository_spec.rb
46
46
  - spec/spec_helper.rb
47
47
  - spec/test_object.rb
48
+ - spec/weak_hash_spec.rb
48
49
  homepage: https://github.com/joelplane/poro_repository
49
50
  licenses: []
50
51
  post_install_message:
@@ -73,3 +74,4 @@ test_files:
73
74
  - spec/poro_repository_spec.rb
74
75
  - spec/spec_helper.rb
75
76
  - spec/test_object.rb
77
+ - spec/weak_hash_spec.rb