gom-filesystem-adapter 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -27,12 +27,17 @@ class GOM::Storage::Filesystem::Adapter < GOM::Storage::Adapter
|
|
27
27
|
read_only_error
|
28
28
|
end
|
29
29
|
|
30
|
+
def count
|
31
|
+
check_setup
|
32
|
+
@drafts.size
|
33
|
+
end
|
34
|
+
|
30
35
|
def collection(view_name, options = { })
|
31
36
|
check_setup
|
37
|
+
configuration = self.configuration
|
32
38
|
view = configuration.views[view_name.to_sym]
|
33
39
|
raise ViewNotFoundError, "there are no view with the name #{view_name}" unless view
|
34
|
-
|
35
|
-
GOM::Object::Collection.new fetcher
|
40
|
+
GOM::Object::Collection.new GOM::Storage::Filesystem::Collection::Fetcher.new(@drafts, view), configuration.name
|
36
41
|
end
|
37
42
|
|
38
43
|
private
|
@@ -28,20 +28,20 @@ class GOM::Storage::Filesystem::Loader
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def load_file_hash(file_hash)
|
31
|
-
file_hash.each do |
|
32
|
-
@drafts[
|
31
|
+
file_hash.each do |object_id, hash|
|
32
|
+
@drafts[object_id] = Builder.new(object_id, hash).draft
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
# Builds a draft out of the file hashes.
|
37
37
|
class Builder
|
38
38
|
|
39
|
-
def initialize(hash)
|
40
|
-
@hash = hash
|
39
|
+
def initialize(object_id, hash)
|
40
|
+
@object_id, @hash = object_id, hash
|
41
41
|
end
|
42
42
|
|
43
43
|
def draft
|
44
|
-
|
44
|
+
initialize_draft
|
45
45
|
set_class_name
|
46
46
|
set_properties
|
47
47
|
set_relations
|
@@ -50,6 +50,10 @@ class GOM::Storage::Filesystem::Loader
|
|
50
50
|
|
51
51
|
private
|
52
52
|
|
53
|
+
def initialize_draft
|
54
|
+
@draft = GOM::Object::Draft.new @object_id
|
55
|
+
end
|
56
|
+
|
53
57
|
def set_class_name
|
54
58
|
@draft.class_name = @hash["class"] || "Object"
|
55
59
|
end
|
@@ -4,12 +4,12 @@ describe GOM::Storage::Filesystem::Adapter do
|
|
4
4
|
|
5
5
|
before :each do
|
6
6
|
@draft = mock GOM::Object::Draft
|
7
|
-
@drafts = mock Hash, :[] => @draft
|
7
|
+
@drafts = mock Hash, :[] => @draft, :size => 1
|
8
8
|
|
9
9
|
@loader = mock GOM::Storage::Filesystem::Loader, :drafts => @drafts
|
10
10
|
GOM::Storage::Filesystem::Loader.stub(:new).and_return(@loader)
|
11
11
|
|
12
|
-
@configuration = mock GOM::Storage::Configuration
|
12
|
+
@configuration = mock GOM::Storage::Configuration, :name => "test_storage"
|
13
13
|
@configuration.stub(:[]).with(:files).and_return("test_files")
|
14
14
|
@adapter = described_class.new @configuration
|
15
15
|
end
|
@@ -107,6 +107,25 @@ describe GOM::Storage::Filesystem::Adapter do
|
|
107
107
|
|
108
108
|
end
|
109
109
|
|
110
|
+
describe "count" do
|
111
|
+
|
112
|
+
before :each do
|
113
|
+
@adapter.setup
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should return the object hash" do
|
117
|
+
@adapter.count.should == 1
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should raise a #{GOM::Storage::Adapter::NoSetupError} if no drafts has been loaded" do
|
121
|
+
@adapter.teardown
|
122
|
+
lambda do
|
123
|
+
@adapter.count
|
124
|
+
end.should raise_error(GOM::Storage::Adapter::NoSetupError)
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
110
129
|
describe "collection" do
|
111
130
|
|
112
131
|
before :each do
|
@@ -61,11 +61,13 @@ describe GOM::Storage::Filesystem::Loader do
|
|
61
61
|
|
62
62
|
it "should convert the file hash into drafts" do
|
63
63
|
draft_one = @loader.drafts["object_1"]
|
64
|
+
draft_one.object_id.should == "object_1"
|
64
65
|
draft_one.class_name.should == "Test::Model"
|
65
66
|
draft_one.properties.should == { "test" => "test value" }
|
66
67
|
draft_one.relations.should == { "related_object" => @proxy }
|
67
68
|
|
68
69
|
draft_two = @loader.drafts["object_2"]
|
70
|
+
draft_two.object_id.should == "object_2"
|
69
71
|
draft_two.class_name.should == "Object"
|
70
72
|
draft_two.properties.should == { "test" => "another test value" }
|
71
73
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 1
|
9
|
+
version: 0.3.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Philipp Br\xC3\xBCll"
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-03-07 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -28,7 +28,8 @@ dependencies:
|
|
28
28
|
segments:
|
29
29
|
- 0
|
30
30
|
- 3
|
31
|
-
|
31
|
+
- 1
|
32
|
+
version: 0.3.1
|
32
33
|
type: :runtime
|
33
34
|
version_requirements: *id001
|
34
35
|
- !ruby/object:Gem::Dependency
|
@@ -70,20 +71,20 @@ files:
|
|
70
71
|
- README.rdoc
|
71
72
|
- LICENSE
|
72
73
|
- Rakefile
|
73
|
-
- lib/gom/storage.rb
|
74
|
-
- lib/gom/filesystem-adapter.rb
|
75
|
-
- lib/gom/storage/filesystem/collection/fetcher.rb
|
76
|
-
- lib/gom/storage/filesystem/collection.rb
|
77
74
|
- lib/gom/storage/filesystem/adapter.rb
|
78
75
|
- lib/gom/storage/filesystem/loader.rb
|
76
|
+
- lib/gom/storage/filesystem/collection/fetcher.rb
|
77
|
+
- lib/gom/storage/filesystem/collection.rb
|
79
78
|
- lib/gom/storage/filesystem.rb
|
80
|
-
-
|
81
|
-
-
|
79
|
+
- lib/gom/filesystem-adapter.rb
|
80
|
+
- lib/gom/storage.rb
|
82
81
|
- spec/gom/storage/filesystem/collection/fetcher_spec.rb
|
83
82
|
- spec/gom/storage/filesystem/adapter_spec.rb
|
84
|
-
- spec/
|
85
|
-
- spec/
|
83
|
+
- spec/gom/storage/filesystem/loader_spec.rb
|
84
|
+
- spec/storage.configuration
|
86
85
|
- spec/spec_helper.rb
|
86
|
+
- spec/acceptance/data/objects.yml
|
87
|
+
- spec/acceptance/adapter_spec.rb
|
87
88
|
has_rdoc: true
|
88
89
|
homepage: http://github.com/phifty/gom-filesystem-adapter
|
89
90
|
licenses: []
|
@@ -117,7 +118,7 @@ signing_key:
|
|
117
118
|
specification_version: 3
|
118
119
|
summary: Filesystem storage adapter for the General Object Mapper.
|
119
120
|
test_files:
|
120
|
-
- spec/gom/storage/filesystem/loader_spec.rb
|
121
121
|
- spec/gom/storage/filesystem/collection/fetcher_spec.rb
|
122
122
|
- spec/gom/storage/filesystem/adapter_spec.rb
|
123
|
+
- spec/gom/storage/filesystem/loader_spec.rb
|
123
124
|
- spec/acceptance/adapter_spec.rb
|