hypostasis 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2759108f29a8bfe2f537ee9893f7276de971bddf
4
- data.tar.gz: f41debb7e9a74283d63700f803a1bd864ed4256f
3
+ metadata.gz: 56eb1dad44b0fb9b42de8fb725486b999ff653f8
4
+ data.tar.gz: fd2f53d2a2ef5e7179e035e077a39bab528497cb
5
5
  SHA512:
6
- metadata.gz: 0b52739c1a6d68c39081b7993f8dd6150ee75d0054c79c852372d77458cd92541d87528b374866eced3a7b7539fa2e8c2b31ccfaef60606b5d12d3c3c11b0bde
7
- data.tar.gz: 6d1db7ff4cd78d563bbefb59cd31fe94524a7e0c05b07413b2da452ec0e6f3ea4f48bcf079ce0be81b030821419445cfc94461ecfdf9096eb59fd6eebda3a451
6
+ metadata.gz: 308cceadb1be00576df9121377e48ce88e7e63f453875a60bca80a0f83ce53b349c00ca25e4cdd9902726605e8a2b5296dc6001693241f7079fdcdd60259852e
7
+ data.tar.gz: 155a90c17f1d50273bcf7b88eda970ac24a8f1a3f39f36df745c9c21f081fa50b8c12d4fb55620dc493e3b44bc05de67d2ac3156c41e820a4cb30fe9b83a1042
@@ -1,49 +1,21 @@
1
- require 'hypostasis/shared/utilities'
2
- require 'hypostasis/shared/namespaced'
3
- require 'hypostasis/shared/fields'
4
- require 'hypostasis/shared/indexes'
5
-
1
+ require 'hypostasis/shared'
6
2
  require 'hypostasis/column_group/persistence'
7
3
  require 'hypostasis/column_group/findable'
8
- require 'hypostasis/column_group/belongs_to'
9
- require 'hypostasis/column_group/has_one'
10
- require 'hypostasis/column_group/has_many'
11
4
 
12
5
  module Hypostasis::ColumnGroup
13
6
  extend ActiveSupport::Concern
14
7
 
8
+ include Hypostasis::Shared
15
9
  include Hypostasis::Shared::Utilities
16
10
  include Hypostasis::Shared::Namespaced
17
11
  include Hypostasis::Shared::Fields
18
12
  include Hypostasis::Shared::Indexes
13
+ include Hypostasis::Shared::BelongsTo
14
+ include Hypostasis::Shared::HasOne
15
+ include Hypostasis::Shared::HasMany
19
16
 
20
17
  include Hypostasis::ColumnGroup::Persistence
21
18
  include Hypostasis::ColumnGroup::Findable
22
19
 
23
- include Hypostasis::ColumnGroup::BelongsTo
24
- include Hypostasis::ColumnGroup::HasOne
25
- include Hypostasis::ColumnGroup::HasMany
26
-
27
- attr_reader :id
28
-
29
- def initialize(*attributes)
30
- self.class.namespace.open
31
-
32
- @fields = {}
33
- self.class.fields.each {|name| @fields[name] = nil}
34
- attributes.each {|hsh| hsh.each {|name, value| @fields[name.to_sym] = value}}
35
- self
36
- end
37
-
38
- def generate_id
39
- @id ||= SecureRandom.uuid
40
- end
41
-
42
- def set_id(id)
43
- @id ||= id.to_s
44
- end
45
-
46
- module ClassMethods
47
- include Hypostasis::DataModels::Utilities
48
- end
20
+ module ClassMethods; end
49
21
  end
@@ -29,17 +29,18 @@ module Hypostasis::ColumnGroup
29
29
 
30
30
  def reconstitute_column_group(keys)
31
31
  attributes = {}
32
- keys.each do |key|
33
- attribute_tuple = key.key.split('\\')[2]
34
- next if attribute_tuple.nil?
35
- unpacked_key = Hypostasis::Tuple.unpack(attribute_tuple)
36
- raw_value = key.value
37
- attributes[unpacked_key.to_a[0].to_sym] = reconstitute_value(unpacked_key, raw_value)
38
- end
32
+ keys.each {|key| attributes.merge(parse_key(key))}
39
33
  document = self.new(attributes)
40
34
  document.set_id(Hypostasis::Tuple.unpack(keys.first.key.split('\\')[1]).to_a[1])
41
35
  document
42
36
  end
37
+
38
+ def parse_key(key)
39
+ attribute_tuple = key.key.split('\\')[2]
40
+ return {} if attribute_tuple.nil?
41
+ unpacked_key = Hypostasis::Tuple.unpack(attribute_tuple)
42
+ {unpacked_key.to_a[0].to_sym => reconstitute_value(unpacked_key, key.value)}
43
+ end
43
44
  end
44
45
  end
45
46
  end
@@ -1,52 +1,25 @@
1
- require 'hypostasis/shared/utilities'
2
- require 'hypostasis/shared/namespaced'
3
- require 'hypostasis/shared/fields'
4
- require 'hypostasis/shared/indexes'
5
-
1
+ require 'hypostasis/shared'
6
2
  require 'hypostasis/document/persistence'
7
3
  require 'hypostasis/document/findable'
8
- require 'hypostasis/document/belongs_to'
9
- require 'hypostasis/document/has_one'
10
- require 'hypostasis/document/has_many'
11
4
 
12
5
  module Hypostasis::Document
13
6
  extend ActiveSupport::Concern
14
7
 
8
+ include Hypostasis::Shared
15
9
  include Hypostasis::Shared::Utilities
16
10
  include Hypostasis::Shared::Namespaced
17
11
  include Hypostasis::Shared::Fields
18
12
  include Hypostasis::Shared::Indexes
13
+ include Hypostasis::Shared::BelongsTo
14
+ include Hypostasis::Shared::HasOne
15
+ include Hypostasis::Shared::HasMany
19
16
 
20
17
  include Hypostasis::Document::Persistence
21
18
  include Hypostasis::Document::Findable
22
- include Hypostasis::Document::BelongsTo
23
- include Hypostasis::Document::HasOne
24
- include Hypostasis::Document::HasMany
25
-
26
- attr_reader :id
27
-
28
- def initialize(*attributes)
29
- self.class.namespace.open
30
-
31
- @fields = {}
32
- self.class.fields.each {|name| @fields[name] = nil}
33
- attributes.each {|hsh| hsh.each {|name, value| @fields[name.to_sym] = value}}
34
- self
35
- end
36
-
37
- def generate_id
38
- @id ||= SecureRandom.uuid
39
- end
40
-
41
- def set_id(id)
42
- @id ||= id.to_s
43
- end
44
19
 
45
20
  def to_bson
46
21
  @fields.to_bson
47
22
  end
48
23
 
49
- module ClassMethods
50
- include Hypostasis::DataModels::Utilities
51
- end
24
+ module ClassMethods; end
52
25
  end
@@ -0,0 +1,33 @@
1
+ require 'hypostasis/shared/utilities'
2
+ require 'hypostasis/shared/namespaced'
3
+ require 'hypostasis/shared/fields'
4
+ require 'hypostasis/shared/indexes'
5
+ require 'hypostasis/shared/belongs_to'
6
+ require 'hypostasis/shared/has_one'
7
+ require 'hypostasis/shared/has_many'
8
+
9
+ module Hypostasis::Shared
10
+ extend ActiveSupport::Concern
11
+
12
+ attr_reader :id
13
+
14
+ def initialize(*attributes)
15
+ self.class.namespace.open
16
+ @fields = {}
17
+ self.class.fields.each {|name| @fields[name] = nil}
18
+ attributes.each {|hsh| hsh.each {|name, value| @fields[name.to_sym] = value}}
19
+ self
20
+ end
21
+
22
+ def generate_id
23
+ @id ||= SecureRandom.uuid
24
+ end
25
+
26
+ def set_id(id)
27
+ @id ||= id.to_s
28
+ end
29
+
30
+ module ClassMethods
31
+ include Hypostasis::DataModels::Utilities
32
+ end
33
+ end
@@ -1,4 +1,4 @@
1
- module Hypostasis::Document
1
+ module Hypostasis::Shared
2
2
  module BelongsTo
3
3
  extend ActiveSupport::Concern
4
4
 
@@ -1,4 +1,4 @@
1
- module Hypostasis::Document
1
+ module Hypostasis::Shared
2
2
  module HasMany
3
3
  extend ActiveSupport::Concern
4
4
 
@@ -1,4 +1,4 @@
1
- module Hypostasis::Document
1
+ module Hypostasis::Shared
2
2
  module HasOne
3
3
  extend ActiveSupport::Concern
4
4
 
@@ -1,3 +1,3 @@
1
1
  module Hypostasis
2
- VERSION = '0.4.2'
2
+ VERSION = '0.4.3'
3
3
  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.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Thompson
@@ -126,10 +126,7 @@ files:
126
126
  - hypostasis.gemspec
127
127
  - lib/hypostasis.rb
128
128
  - lib/hypostasis/column_group.rb
129
- - lib/hypostasis/column_group/belongs_to.rb
130
129
  - lib/hypostasis/column_group/findable.rb
131
- - lib/hypostasis/column_group/has_many.rb
132
- - lib/hypostasis/column_group/has_one.rb
133
130
  - lib/hypostasis/column_group/persistence.rb
134
131
  - lib/hypostasis/connection.rb
135
132
  - lib/hypostasis/data_models.rb
@@ -139,10 +136,7 @@ files:
139
136
  - lib/hypostasis/data_models/key_value.rb
140
137
  - lib/hypostasis/data_models/utilities.rb
141
138
  - lib/hypostasis/document.rb
142
- - lib/hypostasis/document/belongs_to.rb
143
139
  - lib/hypostasis/document/findable.rb
144
- - lib/hypostasis/document/has_many.rb
145
- - lib/hypostasis/document/has_one.rb
146
140
  - lib/hypostasis/document/persistence.rb
147
141
  - lib/hypostasis/errors.rb
148
142
  - lib/hypostasis/ext/bson/date.rb
@@ -150,7 +144,11 @@ files:
150
144
  - lib/hypostasis/key.rb
151
145
  - lib/hypostasis/key_path.rb
152
146
  - lib/hypostasis/namespace.rb
147
+ - lib/hypostasis/shared.rb
148
+ - lib/hypostasis/shared/belongs_to.rb
153
149
  - lib/hypostasis/shared/fields.rb
150
+ - lib/hypostasis/shared/has_many.rb
151
+ - lib/hypostasis/shared/has_one.rb
154
152
  - lib/hypostasis/shared/indexes.rb
155
153
  - lib/hypostasis/shared/namespaced.rb
156
154
  - lib/hypostasis/shared/utilities.rb
@@ -1,18 +0,0 @@
1
- module Hypostasis::ColumnGroup
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
@@ -1,17 +0,0 @@
1
- module Hypostasis::ColumnGroup
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
@@ -1,16 +0,0 @@
1
- module Hypostasis::ColumnGroup
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