polyfill-data 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +12 -0
- data/lib/data.rb +146 -146
- data/lib/polyfill/data/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a03e6512ebc7c374354a31a97017b565d8f2ff9c0fa012d8d48f61e60e8457bb
|
4
|
+
data.tar.gz: b3964f4e5f39d4399e940d4234808c07738a7cc224d651353f4cc1d08daf7068
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '03952e0dd824664e91fc3ff0eb88c68ab26b933c64894a06684afa5b3b0deb7891d0974dbcdde93062eba1ea6cd297098694c1d4b7f2157ec2cfbac75f2feea5'
|
7
|
+
data.tar.gz: 6ae3beceb86909ece7547d01f850e584fdd6411f8bb954b9e09ee987e04a445566f1f8a62e19ca7f19df73f05b27ed80afbdfe5c20361e933171fa0959cb3e52
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## Unreleased
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
### Fixed
|
13
|
+
|
14
|
+
## 1.0.6
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
|
18
|
+
- use `each` to avoid allocating an unused array
|
19
|
+
|
8
20
|
## 1.0.5
|
9
21
|
|
10
22
|
### Fixed
|
data/lib/data.rb
CHANGED
@@ -1,146 +1,146 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "polyfill/data/version"
|
4
|
-
|
5
|
-
if RUBY_VERSION >= "3.2.0"
|
6
|
-
warn "You can remove the 'polyfill-data' gem now."
|
7
|
-
else
|
8
|
-
Object.send(:remove_const, :Data) rescue nil
|
9
|
-
class Data < Object
|
10
|
-
class << self
|
11
|
-
undef_method :new
|
12
|
-
attr_reader :members
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.define(*args, &block)
|
16
|
-
raise ArgumentError if args.any?(/=/)
|
17
|
-
if block
|
18
|
-
mod = Module.new
|
19
|
-
mod.define_singleton_method(:_,) do |klass|
|
20
|
-
klass.class_eval(&block)
|
21
|
-
end
|
22
|
-
arity_converter = mod.method(:_)
|
23
|
-
end
|
24
|
-
klass = ::Class.new(self)
|
25
|
-
|
26
|
-
if args.first.is_a?(String)
|
27
|
-
name = args.shift
|
28
|
-
Data.const_set(name, klass)
|
29
|
-
end
|
30
|
-
|
31
|
-
klass.instance_variable_set(:@members, args)
|
32
|
-
|
33
|
-
klass.define_singleton_method(:new) do |*new_args, **new_kwargs, &block|
|
34
|
-
init_kwargs = if new_args.any?
|
35
|
-
raise ArgumentError, "unknown arguments #{new_args[members.size..].join(', ')}" if new_args.size > members.size
|
36
|
-
Hash[members.take(new_args.size).zip(new_args)]
|
37
|
-
else
|
38
|
-
new_kwargs
|
39
|
-
end
|
40
|
-
|
41
|
-
self.allocate.tap do |instance|
|
42
|
-
instance.send(:initialize, **init_kwargs, &block)
|
43
|
-
end.freeze
|
44
|
-
end
|
45
|
-
|
46
|
-
class << klass
|
47
|
-
alias_method :[], :new
|
48
|
-
undef_method :define
|
49
|
-
end
|
50
|
-
|
51
|
-
args.
|
52
|
-
if klass.method_defined?(arg)
|
53
|
-
raise ArgumentError, "duplicate member #{arg}"
|
54
|
-
end
|
55
|
-
klass.define_method(arg) do
|
56
|
-
@attributes[arg]
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
if arity_converter
|
61
|
-
klass.class_eval(&arity_converter)
|
62
|
-
end
|
63
|
-
|
64
|
-
klass
|
65
|
-
end
|
66
|
-
|
67
|
-
def members
|
68
|
-
self.class.members
|
69
|
-
end
|
70
|
-
|
71
|
-
def initialize(**kwargs)
|
72
|
-
kwargs_size = kwargs.size
|
73
|
-
members_size = members.size
|
74
|
-
|
75
|
-
if kwargs_size > members_size
|
76
|
-
extras = kwargs.reject{|k, _v| members.include?(k) }.keys
|
77
|
-
raise ArgumentError, "unknown arguments #{extras.join(', ')}"
|
78
|
-
elsif kwargs_size < members_size
|
79
|
-
missing = members.select {|k, _v| !kwargs.include?(k) }
|
80
|
-
raise ArgumentError, "missing arguments #{missing.map{ ":#{_1}" }.join(', ')}"
|
81
|
-
end
|
82
|
-
|
83
|
-
@attributes = Hash[members.map {|m| [m,kwargs[m]] }]
|
84
|
-
end
|
85
|
-
|
86
|
-
def deconstruct
|
87
|
-
@attributes.values
|
88
|
-
end
|
89
|
-
|
90
|
-
def deconstruct_keys(array)
|
91
|
-
raise TypeError unless array.is_a?(Array) || array.nil?
|
92
|
-
return @attributes if array&.first.nil?
|
93
|
-
|
94
|
-
@attributes.slice(*array)
|
95
|
-
end
|
96
|
-
|
97
|
-
def to_h(&block)
|
98
|
-
@attributes.to_h(&block)
|
99
|
-
end
|
100
|
-
|
101
|
-
def hash
|
102
|
-
to_h.hash
|
103
|
-
end
|
104
|
-
|
105
|
-
def eql?(other)
|
106
|
-
self.class == other.class && hash == other.hash
|
107
|
-
end
|
108
|
-
|
109
|
-
def ==(other)
|
110
|
-
self.class == other.class && to_h == other.to_h
|
111
|
-
end
|
112
|
-
|
113
|
-
def inspect
|
114
|
-
attribute_markers = @attributes.map do |key, value|
|
115
|
-
insect_key = key.to_s.start_with?("@") ? ":#{key}" : key
|
116
|
-
"#{insect_key}=#{value}"
|
117
|
-
end.join(", ")
|
118
|
-
|
119
|
-
display = ["data", self.class.name, attribute_markers].compact.join(" ")
|
120
|
-
|
121
|
-
"#<#{display}>"
|
122
|
-
end
|
123
|
-
alias_method :to_s, :inspect
|
124
|
-
|
125
|
-
def with(**kwargs)
|
126
|
-
return self if kwargs.empty?
|
127
|
-
|
128
|
-
self.class.new(**@attributes.merge(kwargs))
|
129
|
-
end
|
130
|
-
|
131
|
-
private
|
132
|
-
|
133
|
-
def marshal_dump
|
134
|
-
@attributes
|
135
|
-
end
|
136
|
-
|
137
|
-
def marshal_load(attributes)
|
138
|
-
@attributes = attributes
|
139
|
-
freeze
|
140
|
-
end
|
141
|
-
|
142
|
-
def initialize_copy(source)
|
143
|
-
super.freeze
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "polyfill/data/version"
|
4
|
+
|
5
|
+
if RUBY_VERSION >= "3.2.0"
|
6
|
+
warn "You can remove the 'polyfill-data' gem now."
|
7
|
+
else
|
8
|
+
Object.send(:remove_const, :Data) rescue nil
|
9
|
+
class Data < Object
|
10
|
+
class << self
|
11
|
+
undef_method :new
|
12
|
+
attr_reader :members
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.define(*args, &block)
|
16
|
+
raise ArgumentError if args.any?(/=/)
|
17
|
+
if block
|
18
|
+
mod = Module.new
|
19
|
+
mod.define_singleton_method(:_,) do |klass|
|
20
|
+
klass.class_eval(&block)
|
21
|
+
end
|
22
|
+
arity_converter = mod.method(:_)
|
23
|
+
end
|
24
|
+
klass = ::Class.new(self)
|
25
|
+
|
26
|
+
if args.first.is_a?(String)
|
27
|
+
name = args.shift
|
28
|
+
Data.const_set(name, klass)
|
29
|
+
end
|
30
|
+
|
31
|
+
klass.instance_variable_set(:@members, args)
|
32
|
+
|
33
|
+
klass.define_singleton_method(:new) do |*new_args, **new_kwargs, &block|
|
34
|
+
init_kwargs = if new_args.any?
|
35
|
+
raise ArgumentError, "unknown arguments #{new_args[members.size..].join(', ')}" if new_args.size > members.size
|
36
|
+
Hash[members.take(new_args.size).zip(new_args)]
|
37
|
+
else
|
38
|
+
new_kwargs
|
39
|
+
end
|
40
|
+
|
41
|
+
self.allocate.tap do |instance|
|
42
|
+
instance.send(:initialize, **init_kwargs, &block)
|
43
|
+
end.freeze
|
44
|
+
end
|
45
|
+
|
46
|
+
class << klass
|
47
|
+
alias_method :[], :new
|
48
|
+
undef_method :define
|
49
|
+
end
|
50
|
+
|
51
|
+
args.each do |arg|
|
52
|
+
if klass.method_defined?(arg)
|
53
|
+
raise ArgumentError, "duplicate member #{arg}"
|
54
|
+
end
|
55
|
+
klass.define_method(arg) do
|
56
|
+
@attributes[arg]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
if arity_converter
|
61
|
+
klass.class_eval(&arity_converter)
|
62
|
+
end
|
63
|
+
|
64
|
+
klass
|
65
|
+
end
|
66
|
+
|
67
|
+
def members
|
68
|
+
self.class.members
|
69
|
+
end
|
70
|
+
|
71
|
+
def initialize(**kwargs)
|
72
|
+
kwargs_size = kwargs.size
|
73
|
+
members_size = members.size
|
74
|
+
|
75
|
+
if kwargs_size > members_size
|
76
|
+
extras = kwargs.reject{|k, _v| members.include?(k) }.keys
|
77
|
+
raise ArgumentError, "unknown arguments #{extras.join(', ')}"
|
78
|
+
elsif kwargs_size < members_size
|
79
|
+
missing = members.select {|k, _v| !kwargs.include?(k) }
|
80
|
+
raise ArgumentError, "missing arguments #{missing.map{ ":#{_1}" }.join(', ')}"
|
81
|
+
end
|
82
|
+
|
83
|
+
@attributes = Hash[members.map {|m| [m,kwargs[m]] }]
|
84
|
+
end
|
85
|
+
|
86
|
+
def deconstruct
|
87
|
+
@attributes.values
|
88
|
+
end
|
89
|
+
|
90
|
+
def deconstruct_keys(array)
|
91
|
+
raise TypeError unless array.is_a?(Array) || array.nil?
|
92
|
+
return @attributes if array&.first.nil?
|
93
|
+
|
94
|
+
@attributes.slice(*array)
|
95
|
+
end
|
96
|
+
|
97
|
+
def to_h(&block)
|
98
|
+
@attributes.to_h(&block)
|
99
|
+
end
|
100
|
+
|
101
|
+
def hash
|
102
|
+
to_h.hash
|
103
|
+
end
|
104
|
+
|
105
|
+
def eql?(other)
|
106
|
+
self.class == other.class && hash == other.hash
|
107
|
+
end
|
108
|
+
|
109
|
+
def ==(other)
|
110
|
+
self.class == other.class && to_h == other.to_h
|
111
|
+
end
|
112
|
+
|
113
|
+
def inspect
|
114
|
+
attribute_markers = @attributes.map do |key, value|
|
115
|
+
insect_key = key.to_s.start_with?("@") ? ":#{key}" : key
|
116
|
+
"#{insect_key}=#{value}"
|
117
|
+
end.join(", ")
|
118
|
+
|
119
|
+
display = ["data", self.class.name, attribute_markers].compact.join(" ")
|
120
|
+
|
121
|
+
"#<#{display}>"
|
122
|
+
end
|
123
|
+
alias_method :to_s, :inspect
|
124
|
+
|
125
|
+
def with(**kwargs)
|
126
|
+
return self if kwargs.empty?
|
127
|
+
|
128
|
+
self.class.new(**@attributes.merge(kwargs))
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def marshal_dump
|
134
|
+
@attributes
|
135
|
+
end
|
136
|
+
|
137
|
+
def marshal_load(attributes)
|
138
|
+
@attributes = attributes
|
139
|
+
freeze
|
140
|
+
end
|
141
|
+
|
142
|
+
def initialize_copy(source)
|
143
|
+
super.freeze
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyfill-data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Gay
|
@@ -34,7 +34,7 @@ cert_chain:
|
|
34
34
|
dxkiKqcX+yzo9RJLD9l/E1AWX125r1Fhiif4l6ehdl7Vllc3NQUOm1abdmHtCYjw
|
35
35
|
dG3yPWBWzzN4ovoBRqsuTJbF1wjkCjl5ex5KhfYbeDc=
|
36
36
|
-----END CERTIFICATE-----
|
37
|
-
date: 2023-
|
37
|
+
date: 2023-11-25 00:00:00.000000000 Z
|
38
38
|
dependencies: []
|
39
39
|
description: Add the ruby 3.2 Data class to older rubies. Do nothing in 3.2
|
40
40
|
email:
|
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
requirements: []
|
79
|
-
rubygems_version: 3.
|
79
|
+
rubygems_version: 3.3.5
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: Add the ruby 3.2 Data class to older rubies
|
metadata.gz.sig
CHANGED
Binary file
|