invariable 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +0 -1
- data/lib/invariable/version.rb +1 -1
- data/lib/invariable.rb +13 -15
- 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: 7383243bf91697ac7bf303aacee00e9d05e67ce84f44552c71ec6c1cb5f3f7cd
|
4
|
+
data.tar.gz: c76a032018adade6412f3bef21903bbed7ad9c55b1f7d4584ce01621ee31c2d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f46f26ae8e84432bff462a31b686feb84a1d6eeeeb2d47251a6269d6a86bb9189ab766377e0976f80ac1390c898b1a6d68d2daf8d58c32bd7ccca28194f280d0
|
7
|
+
data.tar.gz: fa0fecd3fd9add3ea732ac6655c20be6e20acda2232c84d0d959397bddc89e050852a34f8d56822c34a5511712a0e2c14484006b321701947438f73bae15e7ae
|
data/.yardopts
CHANGED
data/lib/invariable/version.rb
CHANGED
data/lib/invariable.rb
CHANGED
@@ -161,6 +161,11 @@ module Invariable
|
|
161
161
|
@__attr__.values[arg]
|
162
162
|
end
|
163
163
|
|
164
|
+
# @!visibility private
|
165
|
+
def deconstruct
|
166
|
+
@__attr__.values
|
167
|
+
end
|
168
|
+
|
164
169
|
# @!visibility private
|
165
170
|
def deconstruct_keys(...)
|
166
171
|
@__attr__.deconstruct_keys(...)
|
@@ -195,9 +200,7 @@ module Invariable
|
|
195
200
|
# @return [Enumerator]
|
196
201
|
#
|
197
202
|
def each(&block)
|
198
|
-
|
199
|
-
@__attr__.each_value(&block)
|
200
|
-
self
|
203
|
+
block ? @__attr__.each_value(&block) : to_enum(__method__)
|
201
204
|
end
|
202
205
|
|
203
206
|
#
|
@@ -214,9 +217,7 @@ module Invariable
|
|
214
217
|
# @return [Enumerator]
|
215
218
|
#
|
216
219
|
def each_pair(&block)
|
217
|
-
|
218
|
-
@__attr__.each_pair(&block)
|
219
|
-
self
|
220
|
+
block ? @__attr__.each_pair(&block) : to_enum(__method__)
|
220
221
|
end
|
221
222
|
|
222
223
|
#
|
@@ -233,7 +234,7 @@ module Invariable
|
|
233
234
|
|
234
235
|
# @!visibility private
|
235
236
|
def hash
|
236
|
-
@__hash__ ||= (
|
237
|
+
@__hash__ ||= (@__attr__.values << self.class).hash
|
237
238
|
end
|
238
239
|
|
239
240
|
#
|
@@ -277,11 +278,6 @@ module Invariable
|
|
277
278
|
end
|
278
279
|
alias values to_a
|
279
280
|
|
280
|
-
# @!visibility private
|
281
|
-
def deconstruct
|
282
|
-
@__attr__.values
|
283
|
-
end
|
284
|
-
|
285
281
|
#
|
286
282
|
# @overload to_h
|
287
283
|
# @return [{Symbol => Object}] names and values of all attributes
|
@@ -300,8 +296,8 @@ module Invariable
|
|
300
296
|
# @return [{Object => Object}] pairs returned by the `block`
|
301
297
|
#
|
302
298
|
def to_h(compact: false, &block)
|
303
|
-
return to_compact_h if compact
|
304
299
|
return Hash[@__attr__.map(&block)] if block
|
300
|
+
return __to_compact_h if compact
|
305
301
|
@__attr__.transform_values { |v| v.is_a?(Invariable) ? v.to_h : v }
|
306
302
|
end
|
307
303
|
|
@@ -326,7 +322,7 @@ module Invariable
|
|
326
322
|
|
327
323
|
private
|
328
324
|
|
329
|
-
def
|
325
|
+
def __to_compact_h
|
330
326
|
result = {}
|
331
327
|
@__attr__.each_pair do |key, value|
|
332
328
|
next if value.nil?
|
@@ -367,8 +363,10 @@ module Invariable
|
|
367
363
|
if method_defined?(name)
|
368
364
|
raise(NameError, "attribute already defined - #{name}", caller(4))
|
369
365
|
end
|
370
|
-
define_method(name) { @__attr__[name] }
|
371
366
|
@__attr__[name] = default.is_a?(Class) ? default : default.dup.freeze
|
367
|
+
# accessing "eval-ed" methods is faster than accessing methods defined
|
368
|
+
# via #define_method :/
|
369
|
+
class_eval("def #{name};@__attr__[:#{name}];end")
|
372
370
|
name
|
373
371
|
end
|
374
372
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: invariable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Blumtritt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
An Invariable bundles a number of read-only attributes.
|