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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39d67c12cf8e34e0ac2c0d2c1b4ad850eb3c80aa
4
- data.tar.gz: ef3341c77054ea5b855400b45cb7e7e8b6e39563
3
+ metadata.gz: '04958c784b966e2b0bb05dacc8d8a1b253358596'
4
+ data.tar.gz: 1f564665c929e398bd4af7eeb2cad6a906c1c805
5
5
  SHA512:
6
- metadata.gz: 27aae64c6eff10853db633a665e46509ee67b979827bb0d912e7f09c5dc650b581b592ab257766e24307e9ed7dad9abc2009ade7a010f43e1b1e97dc2d6bf094
7
- data.tar.gz: fbb18af77707515cd3bc2c9622516b4f4c6ad64b3a7c1a0d36667ae92717ca225539dbaf1151150a0bdf02e29d6ec9c541b216f169c5aff0280c0838f48ac4ea
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
- attach_builder_info(entity_class.new(data), repo, options)
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
- entity_class.wrap(data).map { |entity| attach_builder_info(entity, repo, options) }
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
@@ -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
- # These are here to allow for nested data coming from a data source via a repo.
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 __builder_info__
42
- @__builder_info__ ||= {}
43
- end
44
-
45
- def repo
46
- __builder_info__[:repo]
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)}"
@@ -1,3 +1,3 @@
1
1
  module Materialize
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: materialize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Fiser