hypostasis 0.4.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10fcbef73dc4571adad2aff13a7c29c9fd934b09
4
- data.tar.gz: ff7b955b340befb4abcbde39414873a60af7db22
3
+ metadata.gz: 8387e1e541c4ca78130142d9914854c617f649c5
4
+ data.tar.gz: 6fbbd5c6083322414331dc05990e7cc46936c706
5
5
  SHA512:
6
- metadata.gz: 5b8deb5378de71e559c5999e9b4775b8c440b1e6723d3b4f437806971ca47dac622cc04842c723785e1617f13bc274a4c13b125b3169ed26922fb125fd2fa40c
7
- data.tar.gz: 781f1f1a55419d90c6731d151a62a2fa7f9fb05f7d30420385aba3bb45f4f0d8ecb9ddf659f24f4d5af890304b532b8006442945b585561f5e0086342ddedef4
6
+ metadata.gz: 61f5efaa755e97ab2d88e63760a46c2008d9d5e54da3d4dc38a30a6be627ae20f29c8992cf7df14df785501c07c4ee198035bbb1eb91d28ef0f45678b0db1418
7
+ data.tar.gz: e6b367b9111bd0537c37c3198387ba347510becddb0cab4524f8f57640541894d8573864444a9d2a28f67212bed3adec40b45cd00cd974258fb55acde4395e52
@@ -5,6 +5,9 @@ require 'hypostasis/shared/indexes'
5
5
 
6
6
  require 'hypostasis/document/persistence'
7
7
  require 'hypostasis/document/findable'
8
+ require 'hypostasis/document/belongs_to'
9
+ require 'hypostasis/document/has_one'
10
+ require 'hypostasis/document/has_many'
8
11
 
9
12
  module Hypostasis::Document
10
13
  extend ActiveSupport::Concern
@@ -16,6 +19,9 @@ module Hypostasis::Document
16
19
 
17
20
  include Hypostasis::Document::Persistence
18
21
  include Hypostasis::Document::Findable
22
+ include Hypostasis::Document::BelongsTo
23
+ include Hypostasis::Document::HasOne
24
+ include Hypostasis::Document::HasMany
19
25
 
20
26
  attr_reader :id
21
27
 
@@ -0,0 +1,18 @@
1
+ module Hypostasis::Document
2
+ module BelongsTo
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ def belongs_to(klass)
7
+ field_name = "#{klass.to_s}_id"
8
+ accessor_name = klass.to_s
9
+ parent_klass = klass.to_s.classify
10
+ self.class_eval do
11
+ field field_name.to_sym
12
+ index field_name.to_sym
13
+ define_method(accessor_name) { parent_klass.constantize.find(self.send(field_name.to_sym)) }
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -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
@@ -0,0 +1,16 @@
1
+ module Hypostasis::Document
2
+ module HasOne
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ def has_one(klass)
7
+ accessor_name = klass.to_s
8
+ child_klass = klass.to_s.classify
9
+ self_klass = "#{self.to_s.underscore}_id".to_sym
10
+ self.class_eval do
11
+ define_method(accessor_name) { child_klass.constantize.find_where(self_klass => @id).first }
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Hypostasis
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
@@ -1,49 +1,49 @@
1
1
  require 'minitest_helper'
2
2
 
3
- class HasManyOwnerDocument
3
+ class HasManyOwnerColumnGroup
4
4
  include Hypostasis::ColumnGroup
5
5
 
6
- use_namespace 'hasmany_docs'
6
+ use_namespace 'hasmany_columns'
7
7
 
8
8
  field :name
9
9
  field :age
10
10
 
11
- has_many :has_many_child_documents
11
+ has_many :has_many_child_column_groups
12
12
  end
13
13
 
14
- class HasManyChildDocument
14
+ class HasManyChildColumnGroup
15
15
  include Hypostasis::ColumnGroup
16
16
 
17
- use_namespace 'hasmany_docs'
17
+ use_namespace 'hasmany_columns'
18
18
 
19
19
  field :name
20
20
  field :age
21
21
 
22
- belongs_to :has_many_owner_document
22
+ belongs_to :has_many_owner_column_group
23
23
  end
24
24
 
25
25
  describe 'ColumnGroup has_many Relationship' do
26
26
  before do
27
- Hypostasis::Connection.create_namespace 'hasmany_docs', data_model: :column_group
28
- @owner = HasManyOwnerDocument.create(name: 'John', age: '25')
27
+ Hypostasis::Connection.create_namespace 'hasmany_columns', data_model: :column_group
28
+ @owner = HasManyOwnerColumnGroup.create(name: 'John', age: '25')
29
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)
30
+ @children << HasManyChildColumnGroup.create(name: 'James', age: '6', has_many_owner_column_group_id: @owner.id)
31
+ @children << HasManyChildColumnGroup.create(name: 'Susie', age: '4', has_many_owner_column_group_id: @owner.id)
32
+ @children << HasManyChildColumnGroup.create(name: 'Blake', age: '2', has_many_owner_column_group_id: @owner.id)
33
33
  @child = @children.shuffle.first
34
34
  end
35
35
 
36
36
  after do
37
- Hypostasis::Connection.destroy_namespace 'hasmany_docs'
37
+ Hypostasis::Connection.destroy_namespace 'hasmany_columns'
38
38
  end
39
39
 
40
- it { @owner.must_respond_to :has_many_child_documents }
41
- it { @child.must_respond_to :has_many_owner_document }
40
+ it { @owner.must_respond_to :has_many_child_column_groups }
41
+ it { @child.must_respond_to :has_many_owner_column_group }
42
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 }
43
+ it { @owner.has_many_child_column_groups.is_a?(Array).must_equal true }
44
+ it { @owner.has_many_child_column_groups.first.is_a?(HasManyChildColumnGroup).must_equal true }
45
+ it { @owner.has_many_child_column_groups.collect {|doc| doc.id}.must_include @child.id }
46
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 }
47
+ it { @child.has_many_owner_column_group.is_a?(HasManyOwnerColumnGroup).must_equal true }
48
+ it { @child.has_many_owner_column_group.id.must_equal @owner.id }
49
49
  end
@@ -1,44 +1,44 @@
1
1
  require 'minitest_helper'
2
2
 
3
- class HasOneOwnerDocument
3
+ class HasOneOwnerColumnGroup
4
4
  include Hypostasis::ColumnGroup
5
5
 
6
- use_namespace 'hasone_docs'
6
+ use_namespace 'hasone_columns'
7
7
 
8
8
  field :name
9
9
  field :age
10
10
 
11
- has_one :has_one_child_document
11
+ has_one :has_one_child_column_group
12
12
  end
13
13
 
14
- class HasOneChildDocument
14
+ class HasOneChildColumnGroup
15
15
  include Hypostasis::ColumnGroup
16
16
 
17
- use_namespace 'hasone_docs'
17
+ use_namespace 'hasone_columns'
18
18
 
19
19
  field :name
20
20
  field :age
21
21
 
22
- belongs_to :has_one_owner_document
22
+ belongs_to :has_one_owner_column_group
23
23
  end
24
24
 
25
25
  describe 'ColumnGroup has_one Relationship' do
26
26
  before do
27
- Hypostasis::Connection.create_namespace 'hasone_docs', data_model: :column_group
28
- @owner = HasOneOwnerDocument.create(name: 'John', age: '25')
29
- @child = HasOneChildDocument.create(name: 'James', age: '6', has_one_owner_document_id: @owner.id)
27
+ Hypostasis::Connection.create_namespace 'hasone_columns', data_model: :column_group
28
+ @owner = HasOneOwnerColumnGroup.create(name: 'John', age: '25')
29
+ @child = HasOneChildColumnGroup.create(name: 'James', age: '6', has_one_owner_column_group_id: @owner.id)
30
30
  end
31
31
 
32
32
  after do
33
- Hypostasis::Connection.destroy_namespace 'hasone_docs'
33
+ Hypostasis::Connection.destroy_namespace 'hasone_columns'
34
34
  end
35
35
 
36
- it { @owner.must_respond_to :has_one_child_document }
37
- it { @child.must_respond_to :has_one_owner_document }
36
+ it { @owner.must_respond_to :has_one_child_column_group }
37
+ it { @child.must_respond_to :has_one_owner_column_group }
38
38
 
39
- it { @owner.has_one_child_document.is_a?(HasOneChildDocument).must_equal true }
40
- it { @owner.has_one_child_document.id.must_equal @child.id }
39
+ it { @owner.has_one_child_column_group.is_a?(HasOneChildColumnGroup).must_equal true }
40
+ it { @owner.has_one_child_column_group.id.must_equal @child.id }
41
41
 
42
- it { @child.has_one_owner_document.is_a?(HasOneOwnerDocument).must_equal true }
43
- it { @child.has_one_owner_document.id.must_equal @owner.id }
42
+ it { @child.has_one_owner_column_group.is_a?(HasOneOwnerColumnGroup).must_equal true }
43
+ it { @child.has_one_owner_column_group.id.must_equal @owner.id }
44
44
  end
@@ -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
@@ -0,0 +1,44 @@
1
+ require 'minitest_helper'
2
+
3
+ class HasOneOwnerDocument
4
+ include Hypostasis::Document
5
+
6
+ use_namespace 'hasone_docs'
7
+
8
+ field :name
9
+ field :age
10
+
11
+ has_one :has_one_child_document
12
+ end
13
+
14
+ class HasOneChildDocument
15
+ include Hypostasis::Document
16
+
17
+ use_namespace 'hasone_docs'
18
+
19
+ field :name
20
+ field :age
21
+
22
+ belongs_to :has_one_owner_document
23
+ end
24
+
25
+ describe 'Document has_one Relationship' do
26
+ before do
27
+ Hypostasis::Connection.create_namespace 'hasone_docs', data_model: :document
28
+ @owner = HasOneOwnerDocument.create(name: 'John', age: '25')
29
+ @child = HasOneChildDocument.create(name: 'James', age: '6', has_one_owner_document_id: @owner.id)
30
+ end
31
+
32
+ after do
33
+ Hypostasis::Connection.destroy_namespace 'hasone_docs'
34
+ end
35
+
36
+ it { @owner.must_respond_to :has_one_child_document }
37
+ it { @child.must_respond_to :has_one_owner_document }
38
+
39
+ it { @owner.has_one_child_document.is_a?(HasOneChildDocument).must_equal true }
40
+ it { @owner.has_one_child_document.id.must_equal @child.id }
41
+
42
+ it { @child.has_one_owner_document.is_a?(HasOneOwnerDocument).must_equal true }
43
+ it { @child.has_one_owner_document.id.must_equal @owner.id }
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hypostasis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Thompson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-02 00:00:00.000000000 Z
11
+ date: 2014-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fdb
@@ -139,7 +139,10 @@ files:
139
139
  - lib/hypostasis/data_models/key_value.rb
140
140
  - lib/hypostasis/data_models/utilities.rb
141
141
  - lib/hypostasis/document.rb
142
+ - lib/hypostasis/document/belongs_to.rb
142
143
  - lib/hypostasis/document/findable.rb
144
+ - lib/hypostasis/document/has_many.rb
145
+ - lib/hypostasis/document/has_one.rb
143
146
  - lib/hypostasis/document/persistence.rb
144
147
  - lib/hypostasis/errors.rb
145
148
  - lib/hypostasis/ext/bson/date.rb
@@ -158,6 +161,8 @@ files:
158
161
  - test/column/has_one_spec.rb
159
162
  - test/column_group_spec.rb
160
163
  - test/connection_spec.rb
164
+ - test/document/has_many_spec.rb
165
+ - test/document/has_one_spec.rb
161
166
  - test/document/indexing_spec.rb
162
167
  - test/document_spec.rb
163
168
  - test/key_path_spec.rb
@@ -198,6 +203,8 @@ test_files:
198
203
  - test/column/has_one_spec.rb
199
204
  - test/column_group_spec.rb
200
205
  - test/connection_spec.rb
206
+ - test/document/has_many_spec.rb
207
+ - test/document/has_one_spec.rb
201
208
  - test/document/indexing_spec.rb
202
209
  - test/document_spec.rb
203
210
  - test/key_path_spec.rb