simply_serializable 1.1.0 → 1.2.0
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/Gemfile.lock +1 -1
- data/lib/simply_serializable/mixin.rb +12 -5
- data/lib/simply_serializable/serializer.rb +7 -7
- data/lib/simply_serializable/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df935792cdc1ffb0a64da0a012012c8ab5f20babe717dc2d25234b896ec4bd7e
|
4
|
+
data.tar.gz: f3d687f5830508b6b764173340d3091d84fadacc34bf6e487242090ac1fe8bed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: baca71832e1bbc1106b1a179edc1320fefda102cce0934beb7c2eec9680a44fe9d67abbb10d25ab39feadd7f3261a3e1b246e5b74204cc912406d51322d93579
|
7
|
+
data.tar.gz: 774d38c38f1d4d8ed477106001ac17a2e459a573ea6239274be5c4676882e7d369088e725e1f042e254b33bdbb41a9c173d7e3c0ed5efc0739f25fab3d691ca6
|
data/Gemfile.lock
CHANGED
@@ -8,17 +8,24 @@ module SimplySerializable
|
|
8
8
|
super(subclass)
|
9
9
|
end
|
10
10
|
|
11
|
-
def serialize(attributes: [], except:
|
11
|
+
def serialize(attributes: [], except: nil, only: nil)
|
12
12
|
serializable_config[:attributes] = serializable_config[:attributes] |= attributes
|
13
|
-
|
14
|
-
|
13
|
+
unless except.nil?
|
14
|
+
serializable_config[:except] ||= []
|
15
|
+
serializable_config[:except] = serializable_config[:except] |= except
|
16
|
+
end
|
17
|
+
|
18
|
+
unless only.nil?
|
19
|
+
serializable_config[:only] ||= []
|
20
|
+
serializable_config[:only] = serializable_config[:only] |= only
|
21
|
+
end
|
15
22
|
end
|
16
23
|
|
17
24
|
def serializable_config
|
18
25
|
@serializable_config ||= {
|
19
26
|
attributes: [],
|
20
|
-
except:
|
21
|
-
only:
|
27
|
+
except: nil,
|
28
|
+
only: nil
|
22
29
|
}
|
23
30
|
end
|
24
31
|
end
|
@@ -10,17 +10,17 @@ module SimplySerializable
|
|
10
10
|
def initialize(
|
11
11
|
attributes: [],
|
12
12
|
cache: {},
|
13
|
-
except:
|
13
|
+
except: nil,
|
14
14
|
include_readable_instance_variables: true,
|
15
15
|
method_prefix: :serialize,
|
16
16
|
object:,
|
17
|
-
only:
|
17
|
+
only: nil
|
18
18
|
)
|
19
19
|
@object = object
|
20
20
|
@attributes = attributes
|
21
21
|
@include_readable_instance_variables = include_readable_instance_variables
|
22
|
-
@except = except
|
23
|
-
@only = only
|
22
|
+
@except = except&.map(&:to_sym)
|
23
|
+
@only = only&.map(&:to_sym)
|
24
24
|
@method_prefix = method_prefix
|
25
25
|
@cache = cache
|
26
26
|
@cache[cache_key] = nil
|
@@ -91,12 +91,12 @@ module SimplySerializable
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def populate_attributes
|
94
|
-
raise 'You cannot pass only and except values. Please choose one.' if only.
|
94
|
+
raise 'You cannot pass only and except values. Please choose one.' if !only.nil? && !except.nil?
|
95
95
|
|
96
96
|
@attributes |= instance_vars_with_readers if @include_readable_instance_variables
|
97
97
|
|
98
|
-
@attributes =
|
99
|
-
@attributes = attributes - except
|
98
|
+
@attributes = only unless only.nil?
|
99
|
+
@attributes = attributes - except unless except.nil?
|
100
100
|
attributes
|
101
101
|
end
|
102
102
|
|