primalize 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/primalize/many.rb +27 -1
- data/lib/primalize/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 448491f1045de5e13c32b1654908a81aef3a4088
|
4
|
+
data.tar.gz: 0fabc3d5579b65702bf1b697a515ff5c7c01e41a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e00310261eb2d595fbab0242da634142a8ef3e31a62bcca8ddeb1b5cc71021cad5cf697a8e386ce5ad62e64d7223a12cd5ef825b5db9b6897581ff3f26735bb1
|
7
|
+
data.tar.gz: 03ed8baf130751558ae80948c6562fb0f61b2906edc9869a3f16168b88abf7f21ae6c32a541aeb246b8a3960fc8fa827ff6f44a71252472a50bdb4c4482c9eec
|
data/lib/primalize/many.rb
CHANGED
@@ -35,6 +35,25 @@ module Primalize
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def self.optional serializer_class
|
39
|
+
Class.new(Optional) do
|
40
|
+
define_method :initialize do |object|
|
41
|
+
return if object.nil?
|
42
|
+
|
43
|
+
@object = object
|
44
|
+
@serializer = serializer_class.new(object)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Optional
|
50
|
+
def call
|
51
|
+
return nil if @object.nil?
|
52
|
+
|
53
|
+
@serializer.call
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
38
57
|
class Enumerable
|
39
58
|
def initialize enumerable
|
40
59
|
validate! enumerable
|
@@ -69,7 +88,14 @@ module Primalize
|
|
69
88
|
end
|
70
89
|
|
71
90
|
def validate_attributes! attributes
|
72
|
-
|
91
|
+
attr_map = self.class.attributes
|
92
|
+
all_required_attributes_provided = attr_map
|
93
|
+
.each_key
|
94
|
+
.all? do |key|
|
95
|
+
attributes[key] || (attr_map[key].superclass == Optional)
|
96
|
+
end
|
97
|
+
|
98
|
+
unless all_required_attributes_provided
|
73
99
|
non_nil_keys = attributes
|
74
100
|
.select { |_attr, value| value }
|
75
101
|
.map { |attr, _value| attr }
|
data/lib/primalize/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: primalize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Gaskins
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
111
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.6.
|
112
|
+
rubygems_version: 2.6.12
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Type-checked serializers for your Ruby objects
|