invariable 0.1.5 → 0.1.7
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 +20 -23
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99bb0d3d7fca01b1a3d5bdbe965a43f4dd5bbc95f90e9278a81eeb7b00448c86
|
4
|
+
data.tar.gz: 90adb109963224f9e4b5638e6065ab8366d78e4be3f63f7aa99c7f321feeaeaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65052fcc48d1ef7259424c0e7abb63d6f47cbf813de785ce39df80aaa0d566175021d0070ffccde09a36c92107acdd93260385f643cc6e07e803c0cee3612a76
|
7
|
+
data.tar.gz: 692ba41bae06488d1ada5be7f02aa4a3045538999f38340b1fea583113061363193553885cceddb80813d37543901af59afd093ef849ee7c0f12d1183c56078a
|
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,17 +234,17 @@ 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
|
-
|
241
|
-
|
240
|
+
alias __to_s to_s
|
241
|
+
private :__to_s
|
242
|
+
|
243
|
+
# @!visibility private
|
242
244
|
def inspect
|
243
245
|
attributes = @__attr__.map { |k, v| "#{k}: #{v.inspect}" }
|
244
|
-
"
|
246
|
+
"#{__to_s[..-2]} #{attributes.join(', ')}>"
|
245
247
|
end
|
246
|
-
alias to_s inspect
|
247
248
|
|
248
249
|
#
|
249
250
|
# @return [Boolean] whether the given name is a valid attribute name
|
@@ -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,17 +363,18 @@ 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
|
|
375
373
|
def __attr__init
|
376
374
|
if superclass.instance_variable_defined?(:@__attr__)
|
377
|
-
Hash[superclass.instance_variable_get(:@__attr__)]
|
378
|
-
else
|
379
|
-
{}.compare_by_identity
|
375
|
+
return Hash[superclass.instance_variable_get(:@__attr__)]
|
380
376
|
end
|
377
|
+
{}.compare_by_identity
|
381
378
|
end
|
382
379
|
end
|
383
380
|
private_constant(:InvariableClassMethods)
|
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.7
|
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-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
An Invariable bundles a number of read-only attributes.
|
@@ -41,14 +41,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
41
|
requirements:
|
42
42
|
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
44
|
+
version: 3.0.0
|
45
45
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '0'
|
50
50
|
requirements: []
|
51
|
-
rubygems_version: 3.
|
51
|
+
rubygems_version: 3.4.1
|
52
52
|
signing_key:
|
53
53
|
specification_version: 4
|
54
54
|
summary: The Invariable data class for Ruby.
|