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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f36086871785c4f7a5db75ed9e4b9272a4285c80c76335c7e09bd4eccdb2c939
4
- data.tar.gz: 9936ecd659270cedddfd0d0d18fac176783b97aa7f9c52739fbe45abf1a107d8
3
+ metadata.gz: 744672f26853b28ea94b9a5cdc57c154784210f5bc845628dcdf874e54712db1
4
+ data.tar.gz: 759c1c816f8118589c56849a819f550a5b423653c262b7c5d802f7cfbe80065b
5
5
  SHA512:
6
- metadata.gz: d4800195157b45b817aa2a700113c126b466b9ec53c342fb6e4473ae4bf6d9b463fe05b839ef65f1aa12db1d4e0a128d7026b10b6eacf5bb5e31c4891de1349b
7
- data.tar.gz: 6893d0692e160627a8a2e1f5ed32de5181dde889778874d05955469e12074c90d7a3f377321dea7b25dd2178e3a97eddf55986f5ea65d6fe4e64f0130e9f0c4b
6
+ metadata.gz: d4c6b8e5073c818e434e947e915cfb0e02ab5c17606129398968715e0337d710ddcb9ae4f2c4237cb2a7dead4cd73897d7e6fe38e033fccd492fdbe6faa958af
7
+ data.tar.gz: e4ec51d139746ea55a389de5e9c93cbf16b52e4ae4357599719736613228902530b2a14d54546e5cdd0da3150fe70290184572f1954f8b32c6a1ea566cdae0e3
@@ -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 && val == (Proc === @default ? @default.call(obj, @id) : @default)
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
@@ -4,6 +4,6 @@
4
4
  module FIRM
5
5
 
6
6
  # FIRM version
7
- VERSION = "1.1.0"
7
+ VERSION = "1.1.2"
8
8
 
9
9
  end
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.0
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-05 00:00:00.000000000 Z
11
+ date: 2024-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake