hypostasis 0.2.2 → 0.2.3
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.
- checksums.yaml +4 -4
- data/lib/hypostasis/document.rb +2 -0
- data/lib/hypostasis/document/has_many.rb +17 -0
- data/lib/hypostasis/version.rb +1 -1
- data/test/document/has_many_spec.rb +49 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6caf9a586e59a87fa6af2c7403f8f6a111367f45
|
4
|
+
data.tar.gz: acb363691d0bede7084ae87720b35ed7eee871d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 461374040933e42113e95cfb5c3f31746df9a9c99732cf5cb72f4781ad0bcc40f8f909d5c5ddc9007f8937f66652d6e63388498212c366771e849284af3da417
|
7
|
+
data.tar.gz: 1811b054f4ffd51b3aa17d01615bc49aeec934adf50b19ef9d6bdbdf009cad40eb334f381cfdc6782a69dd10c2b2d41ae008326ba8b56c21bcdf3f76e92903a7
|
data/lib/hypostasis/document.rb
CHANGED
@@ -8,6 +8,7 @@ require 'hypostasis/document/persistence'
|
|
8
8
|
require 'hypostasis/document/findable'
|
9
9
|
require 'hypostasis/document/belongs_to'
|
10
10
|
require 'hypostasis/document/has_one'
|
11
|
+
require 'hypostasis/document/has_many'
|
11
12
|
|
12
13
|
module Hypostasis::Document
|
13
14
|
extend ActiveSupport::Concern
|
@@ -20,6 +21,7 @@ module Hypostasis::Document
|
|
20
21
|
|
21
22
|
include Hypostasis::Document::BelongsTo
|
22
23
|
include Hypostasis::Document::HasOne
|
24
|
+
include Hypostasis::Document::HasMany
|
23
25
|
|
24
26
|
attr_reader :id
|
25
27
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Hypostasis::Document
|
2
|
+
module HasMany
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def has_many(klass)
|
7
|
+
singular_klass = klass.to_s.singularize
|
8
|
+
accessor_name = klass.to_s
|
9
|
+
child_klass = singular_klass.to_s.classify
|
10
|
+
self_klass = "#{self.to_s.underscore}_id".to_sym
|
11
|
+
self.class_eval do
|
12
|
+
define_method(accessor_name) { child_klass.constantize.find_where(self_klass => @id) }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/hypostasis/version.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
class HasManyOwnerDocument
|
4
|
+
include Hypostasis::Document
|
5
|
+
|
6
|
+
use_namespace 'hasmany_docs'
|
7
|
+
|
8
|
+
field :name
|
9
|
+
field :age
|
10
|
+
|
11
|
+
has_many :has_many_child_documents
|
12
|
+
end
|
13
|
+
|
14
|
+
class HasManyChildDocument
|
15
|
+
include Hypostasis::Document
|
16
|
+
|
17
|
+
use_namespace 'hasmany_docs'
|
18
|
+
|
19
|
+
field :name
|
20
|
+
field :age
|
21
|
+
|
22
|
+
belongs_to :has_many_owner_document
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'Document has_many Relationship' do
|
26
|
+
before do
|
27
|
+
Hypostasis::Connection.create_namespace 'hasmany_docs', data_model: :document
|
28
|
+
@owner = HasManyOwnerDocument.create(name: 'John', age: '25')
|
29
|
+
@children = []
|
30
|
+
@children << HasManyChildDocument.create(name: 'James', age: '6', has_many_owner_document_id: @owner.id)
|
31
|
+
@children << HasManyChildDocument.create(name: 'Susie', age: '4', has_many_owner_document_id: @owner.id)
|
32
|
+
@children << HasManyChildDocument.create(name: 'Blake', age: '2', has_many_owner_document_id: @owner.id)
|
33
|
+
@child = @children.shuffle.first
|
34
|
+
end
|
35
|
+
|
36
|
+
after do
|
37
|
+
Hypostasis::Connection.destroy_namespace 'hasmany_docs'
|
38
|
+
end
|
39
|
+
|
40
|
+
it { @owner.must_respond_to :has_many_child_documents }
|
41
|
+
it { @child.must_respond_to :has_many_owner_document }
|
42
|
+
|
43
|
+
it { @owner.has_many_child_documents.is_a?(Array).must_equal true }
|
44
|
+
it { @owner.has_many_child_documents.first.is_a?(HasManyChildDocument).must_equal true }
|
45
|
+
it { @owner.has_many_child_documents.collect {|doc| doc.id}.must_include @child.id }
|
46
|
+
|
47
|
+
it { @child.has_many_owner_document.is_a?(HasManyOwnerDocument).must_equal true }
|
48
|
+
it { @child.has_many_owner_document.id.must_equal @owner.id }
|
49
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hypostasis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Thompson
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/hypostasis/document/belongs_to.rb
|
107
107
|
- lib/hypostasis/document/fields.rb
|
108
108
|
- lib/hypostasis/document/findable.rb
|
109
|
+
- lib/hypostasis/document/has_many.rb
|
109
110
|
- lib/hypostasis/document/has_one.rb
|
110
111
|
- lib/hypostasis/document/indexes.rb
|
111
112
|
- lib/hypostasis/document/namespaced.rb
|
@@ -117,6 +118,7 @@ files:
|
|
117
118
|
- lib/hypostasis/version.rb
|
118
119
|
- provision.sh
|
119
120
|
- test/connection_spec.rb
|
121
|
+
- test/document/has_many_spec.rb
|
120
122
|
- test/document/has_one_spec.rb
|
121
123
|
- test/document_spec.rb
|
122
124
|
- test/key_path_spec.rb
|
@@ -151,6 +153,7 @@ specification_version: 4
|
|
151
153
|
summary: A layer for FoundationDB providing multiple data models for Ruby.
|
152
154
|
test_files:
|
153
155
|
- test/connection_spec.rb
|
156
|
+
- test/document/has_many_spec.rb
|
154
157
|
- test/document/has_one_spec.rb
|
155
158
|
- test/document_spec.rb
|
156
159
|
- test/key_path_spec.rb
|