firm 1.1.0 → 1.1.2
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 +18 -1
- 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: 744672f26853b28ea94b9a5cdc57c154784210f5bc845628dcdf874e54712db1
|
4
|
+
data.tar.gz: 759c1c816f8118589c56849a819f550a5b423653c262b7c5d802f7cfbe80065b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4c6b8e5073c818e434e947e915cfb0e02ab5c17606129398968715e0337d710ddcb9ae4f2c4237cb2a7dead4cd73897d7e6fe38e033fccd492fdbe6faa958af
|
7
|
+
data.tar.gz: e4ec51d139746ea55a389de5e9c93cbf16b52e4ae4357599719736613228902530b2a14d54546e5cdd0da3150fe70290184572f1954f8b32c6a1ea566cdae0e3
|
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])
|
@@ -93,7 +110,7 @@ module FIRM
|
|
93
110
|
end
|
94
111
|
|
95
112
|
def optional?(obj, val)
|
96
|
-
@optional &&
|
113
|
+
@optional && (Proc === @default ? @default.call(obj, @id) : @default) == val
|
97
114
|
end
|
98
115
|
private :optional?
|
99
116
|
|
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.2
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|