firm 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/firm/serializable.rb +17 -0
- data/lib/firm/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bde55f78b14c4b8c8cac20c709c2826391616cf5d30972bcdeff2613d9389f5
|
4
|
+
data.tar.gz: f4e7a9b3269ea524699693968c88d75372f6bf51dbe54c7e61b3bee349da3b71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3768d2dda3e137c33b54ecfe27eda8f052c9eb8e21809e9e8f82eb434f9ce381fdf5cd430d9d118aacb75a6047c4db2bd175d2e9937be3fccc6b587f8cc0b683
|
7
|
+
data.tar.gz: 329dff1413b582f472b099181769c16afc91aeaa9fe6b827b1cb753be68df14d6dbda11e5d60f3da77e97feb22833b7b78db0a231b09a605c5f78d79845f16e0
|
data/lib/firm/serializable.rb
CHANGED
@@ -11,6 +11,7 @@ module FIRM
|
|
11
11
|
|
12
12
|
class Exception < RuntimeError; end
|
13
13
|
|
14
|
+
# This class encapsulates a serializable property definition.
|
14
15
|
class Property
|
15
16
|
def initialize(klass, prop, proc=nil, force: false, handler: nil, optional: false, &block)
|
16
17
|
::Kernel.raise ArgumentError, "Invalid property id [#{prop}]" unless ::String === prop || ::Symbol === prop
|
@@ -70,6 +71,11 @@ module FIRM
|
|
70
71
|
|
71
72
|
attr_reader :id
|
72
73
|
|
74
|
+
# Serializes the defined property for the given object and inserts the serialized data
|
75
|
+
# into the given data object unless included in the given excludes list.
|
76
|
+
# @param [Object] obj
|
77
|
+
# @param [Object] data hash-like object
|
78
|
+
# @param [Array<Symbol>] excludes
|
73
79
|
def serialize(obj, data, excludes)
|
74
80
|
unless excludes.include?(@id)
|
75
81
|
val = getter.call(obj)
|
@@ -86,6 +92,17 @@ module FIRM
|
|
86
92
|
end
|
87
93
|
end
|
88
94
|
|
95
|
+
# Returns the (unserialized) property value for the given object.
|
96
|
+
# @param [Object] obj
|
97
|
+
def get(obj)
|
98
|
+
getter.call(obj)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Restores the defined property for the given object using the deserialized data
|
102
|
+
# extracted from the given data object.
|
103
|
+
# @param [Object] obj
|
104
|
+
# @param [Object] data hash-like object
|
105
|
+
# @return [void]
|
89
106
|
def deserialize(obj, data)
|
90
107
|
if data.has_key?(@id)
|
91
108
|
setter.call(obj, data[@id])
|
data/lib/firm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Corino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|