materialize 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/materialize/entity.rb +3 -33
- data/lib/materialize/version.rb +1 -1
- data/materialize-0.3.5.gem +0 -0
- metadata +2 -2
- data/LICENSE.txt +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63cce4807d7438dcd0c3a4ea2d1a86db888e73f0
|
4
|
+
data.tar.gz: 1432d5e143568622616c933951c08452371b5d7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7496b0a4ac9caa95f074f2e5e031e8c97ae4a83a7144e6895aa1850203ee6234bc0ed5336af9da493db7c12773b59c37aadbac32fd308acb49e9aee9a79284a1
|
7
|
+
data.tar.gz: 1fae6166f03bd065f7f1137825f58bc155db5081f834acc6ae6eddebd491cb9629b3edfbee299947ae9fe1c18dc0862a0bede6951262cdb3e930d550db06c841
|
data/lib/materialize/entity.rb
CHANGED
@@ -8,17 +8,9 @@ module Materialize
|
|
8
8
|
entities_data.map { |entity_data| new(entity_data) }
|
9
9
|
end
|
10
10
|
|
11
|
-
attr_writer :__builder_info__
|
12
|
-
|
13
11
|
def initialize(attributes)
|
14
12
|
raise "Attributes must be a hash" unless attributes.is_a?(Hash)
|
15
13
|
|
16
|
-
@__repo__ = attributes[:__repo__]
|
17
|
-
@__options__ = attributes[:__options__]
|
18
|
-
|
19
|
-
attributes.delete(:__repo__)
|
20
|
-
attributes.delete(:__options__)
|
21
|
-
|
22
14
|
attributes.each_pair do |key, value|
|
23
15
|
value = attempt_entity_conversion(key, value) if collection?(value)
|
24
16
|
instance_variable_set("@#{key}", value)
|
@@ -30,30 +22,13 @@ module Materialize
|
|
30
22
|
|
31
23
|
private
|
32
24
|
|
33
|
-
# START REMARKS ---->
|
34
|
-
|
35
|
-
# __repo__ and __options__ are here to allow for nested data coming from a data source via a repo.
|
36
|
-
# e.g.
|
37
|
-
# blog_post = {
|
38
|
-
# id: 1,
|
39
|
-
# title: 'TDD is dead (wait, what?)'
|
40
|
-
# ...
|
41
|
-
# comments: [...]
|
42
|
-
# }
|
43
|
-
#
|
44
|
-
# In this case, we need to queue a builder, which requires a repo and options (see repo & builder classes).
|
45
|
-
# WARNING:
|
46
|
-
# This should be avoided for deeply nested data, especially when the leaves look up extra data!
|
47
|
-
|
48
|
-
attr_reader :__repo__, :__options__
|
49
|
-
|
50
25
|
def attempt_entity_conversion(key, value)
|
51
26
|
if class_exists?(covert_to_entity_class_name(key))
|
52
|
-
klass = Module.const_get(
|
27
|
+
klass = Module.const_get(covert_to_entity_class_name(key))
|
53
28
|
if value.is_a?(Array)
|
54
|
-
klass.
|
29
|
+
klass.wrap(value)
|
55
30
|
else
|
56
|
-
klass.
|
31
|
+
klass.new(value)
|
57
32
|
end
|
58
33
|
else
|
59
34
|
value
|
@@ -66,15 +41,10 @@ module Materialize
|
|
66
41
|
value.is_a? Enumerable
|
67
42
|
end
|
68
43
|
|
69
|
-
|
70
44
|
def covert_to_entity_class_name(key)
|
71
45
|
"Entities::#{base_name_for(key)}"
|
72
46
|
end
|
73
47
|
|
74
|
-
def builder_class_name_for(key)
|
75
|
-
"#{base_name_for(key)}Builder"
|
76
|
-
end
|
77
|
-
|
78
48
|
def base_name_for(key)
|
79
49
|
key.to_s.singularize.split('_').collect(&:capitalize).join
|
80
50
|
end
|
data/lib/materialize/version.rb
CHANGED
Binary file
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Fiser
|
@@ -92,7 +92,6 @@ files:
|
|
92
92
|
- ".rspec"
|
93
93
|
- ".travis.yml"
|
94
94
|
- Gemfile
|
95
|
-
- LICENSE.txt
|
96
95
|
- README.md
|
97
96
|
- Rakefile
|
98
97
|
- bin/console
|
@@ -107,6 +106,7 @@ files:
|
|
107
106
|
- lib/materialize/response.rb
|
108
107
|
- lib/materialize/utils.rb
|
109
108
|
- lib/materialize/version.rb
|
109
|
+
- materialize-0.3.5.gem
|
110
110
|
- materialize.gemspec
|
111
111
|
homepage: http://bluebear.io
|
112
112
|
licenses:
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2017 Stephen Fiser
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|