materialize 0.3.0 → 0.3.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 +4 -4
- data/lib/materialize/base_builder.rb +7 -7
- data/lib/materialize/entity.rb +14 -18
- data/lib/materialize/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '04958c784b966e2b0bb05dacc8d8a1b253358596'
|
4
|
+
data.tar.gz: 1f564665c929e398bd4af7eeb2cad6a906c1c805
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d1baa1ba05898ee752b17c93ffe84e7671fb3a2bdc079a4d9d1078a50747729392322bf0ac38993a9144bdfda8f7bc4981c2dbb0353d5b2bf9143f9e24361a4
|
7
|
+
data.tar.gz: e76ed92f6dc1df83cd158dd7ce9078dd5ca76820bc5ced8b382d7fc7be83d6362d1d7c063fbbd5cfe3124c803a96563b38a0e9568edc0a825efa09860307cd55
|
@@ -1,14 +1,19 @@
|
|
1
|
+
require 'pry'
|
2
|
+
|
1
3
|
module Materialize
|
2
4
|
class BaseBuilder
|
3
5
|
extend Concurrent
|
4
6
|
class << self
|
5
7
|
|
8
|
+
# Need to attach builder info somehow before we call initialize!
|
6
9
|
def build(data, repo, options)
|
7
|
-
|
10
|
+
data = data.merge({ __repo__: repo, __options__: options })
|
11
|
+
entity_class.new(data)
|
8
12
|
end
|
9
13
|
|
10
14
|
def build_all(data, repo, options)
|
11
|
-
|
15
|
+
datas = data.map { |d| d.merge({ __repo__: repo, __options__: options }) }
|
16
|
+
entity_class.wrap(datas)
|
12
17
|
end
|
13
18
|
|
14
19
|
def entity_class
|
@@ -17,11 +22,6 @@ module Materialize
|
|
17
22
|
|
18
23
|
private
|
19
24
|
|
20
|
-
def attach_builder_info(entity, repo, options)
|
21
|
-
entity.__builder_info__ = { repo: repo, options: options }
|
22
|
-
entity
|
23
|
-
end
|
24
|
-
|
25
25
|
def entity_base_class_name
|
26
26
|
"#{self.name[0..-8]}".split('::').last
|
27
27
|
end
|
data/lib/materialize/entity.rb
CHANGED
@@ -11,6 +11,12 @@ module Materialize
|
|
11
11
|
def initialize(attributes)
|
12
12
|
raise "Attributes must be a hash" unless attributes.is_a?(Hash)
|
13
13
|
|
14
|
+
@__repo__ = attributes[:__repo__]
|
15
|
+
@__options__ = attributes[:__options__]
|
16
|
+
|
17
|
+
attributes.delete(:__repo__)
|
18
|
+
attributes.delete(:__options__)
|
19
|
+
|
14
20
|
attributes.each_pair do |key, value|
|
15
21
|
value = attempt_entity_conversion(key, value) if collection?(value)
|
16
22
|
instance_variable_set("@#{key}", value)
|
@@ -24,7 +30,7 @@ module Materialize
|
|
24
30
|
|
25
31
|
# START REMARKS ---->
|
26
32
|
|
27
|
-
#
|
33
|
+
# __repo__ and __options__ are here to allow for nested data coming from a data source via a repo.
|
28
34
|
# e.g.
|
29
35
|
# blog_post = {
|
30
36
|
# id: 1,
|
@@ -37,17 +43,14 @@ module Materialize
|
|
37
43
|
# WARNING:
|
38
44
|
# This should be avoided for deeply nested data, especially when the leaves look up extra data!
|
39
45
|
|
46
|
+
attr_reader :__repo__, :__options__
|
40
47
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
def options
|
50
|
-
__builder_info__[:options]
|
48
|
+
def attempt_entity_conversion(key, value)
|
49
|
+
if class_exists?(covert_to_entity_class_name(key))
|
50
|
+
Module.const_get(builder_class_name_for(key)).build_all(value, __repo__, __options__)
|
51
|
+
else
|
52
|
+
value
|
53
|
+
end
|
51
54
|
end
|
52
55
|
|
53
56
|
# ----> END REMARKS
|
@@ -56,13 +59,6 @@ module Materialize
|
|
56
59
|
value.is_a? Enumerable
|
57
60
|
end
|
58
61
|
|
59
|
-
def attempt_entity_conversion(key, value)
|
60
|
-
if class_exists?(covert_to_entity_class_name(key))
|
61
|
-
Module.const_get(builder_class_name_for(key)).build_all(value, repo, options)
|
62
|
-
else
|
63
|
-
value
|
64
|
-
end
|
65
|
-
end
|
66
62
|
|
67
63
|
def covert_to_entity_class_name(key)
|
68
64
|
"Entities::#{base_name_for(key)}"
|
data/lib/materialize/version.rb
CHANGED