u-struct 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +2 -1
- data/README.md +1 -1
- data/lib/micro/struct/creator/create_module.rb +33 -18
- data/lib/micro/struct/features.rb +1 -2
- data/lib/micro/struct/version.rb +1 -1
- data/lib/micro/struct.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bebaeb99b56b26288a87f8907532e194a4388563a11ed486c90d203c34d9e951
|
4
|
+
data.tar.gz: 66d1f615dcaa99c713d24b7ea375f00293396fe91d2314be223a487cfa90caa8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4131a340a7a5981a60a177a2a1c59846f12693053eb80cd77e289e83a3602e10df31b694c8bb8a0fbb9a8d60886ce4b0e27424cce27a1ae2e513570d981c0c67
|
7
|
+
data.tar.gz: 2ed2f7a1a80265ace687639e575f5395f3cb1c663ac0c4b5dc044a52a2ba321540942523a6a7f0b9377df6d2a4569e029b35a8f1345e861ab23cd0f5cd0d885b
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
```ruby
|
24
24
|
# Like in a regular Struct, you can define one or many attributes.
|
25
|
-
# But all of will be required by default.
|
25
|
+
# But all of them will be required by default.
|
26
26
|
|
27
27
|
Micro::Struct.new(:first_name, :last_name, ...)
|
28
28
|
|
@@ -7,41 +7,56 @@ class Micro::Struct::Creator
|
|
7
7
|
def with(required_members, optional_members, features)
|
8
8
|
container = Module.new
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def_initialize(container, required_members, optional_members)
|
11
|
+
def_triple_eq(container)
|
12
|
+
def_members(container)
|
13
|
+
def_to_proc(container, features)
|
13
14
|
|
14
15
|
container
|
15
16
|
end
|
16
17
|
|
17
18
|
private
|
18
19
|
|
19
|
-
def
|
20
|
+
def def_initialize(container, required_members, optional_members)
|
20
21
|
required = "#{required_members.join(':, ')}#{':' unless required_members.empty?}"
|
21
22
|
optional = "#{optional_members.join(': nil, ')}#{': nil' unless optional_members.empty?}"
|
22
23
|
|
23
24
|
method_arguments = [required, optional].reject(&:empty?).join(', ')
|
24
25
|
struct_arguments = (required_members + optional_members).join(', ')
|
25
26
|
|
27
|
+
# The .new() method will require all required keyword arguments.
|
28
|
+
# We are doing this because the Struct constructor keyword init option treats everything as optional.
|
29
|
+
#
|
30
|
+
container.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
31
|
+
def self.new(#{method_arguments}) # def self.new(a:, b:) do
|
32
|
+
Struct.send(:new, #{struct_arguments}) # Struct.send(:new, a, b)
|
33
|
+
end # end
|
34
|
+
RUBY
|
35
|
+
end
|
36
|
+
|
37
|
+
def def_triple_eq(container)
|
26
38
|
container.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
def self.new(#{method_arguments}) # def self.new(a:, b:) do
|
31
|
-
Struct.send(:new, #{struct_arguments}) # Struct.send(:new, a, b)
|
32
|
-
end # end
|
33
|
-
|
34
|
-
def self.members
|
35
|
-
Struct.members
|
36
|
-
end
|
39
|
+
def self.===(other)
|
40
|
+
Struct === other
|
41
|
+
end
|
37
42
|
RUBY
|
38
43
|
end
|
39
44
|
|
40
|
-
def
|
45
|
+
def def_members(container)
|
46
|
+
container.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
47
|
+
def self.members
|
48
|
+
Struct.members
|
49
|
+
end
|
50
|
+
RUBY
|
51
|
+
end
|
52
|
+
|
53
|
+
def def_to_proc(container, features)
|
54
|
+
return unless features[:to_proc]
|
55
|
+
|
41
56
|
container.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
42
|
-
|
43
|
-
|
44
|
-
|
57
|
+
def self.to_proc
|
58
|
+
->(hash) { new(**hash) }
|
59
|
+
end
|
45
60
|
RUBY
|
46
61
|
end
|
47
62
|
end
|
data/lib/micro/struct/version.rb
CHANGED
data/lib/micro/struct.rb
CHANGED
@@ -7,7 +7,7 @@ require_relative 'struct/normalize_names'
|
|
7
7
|
|
8
8
|
module Micro
|
9
9
|
# Like in a regular Struct, you can define one or many attributes.
|
10
|
-
# But all of will be required by default.
|
10
|
+
# But all of them will be required by default.
|
11
11
|
#
|
12
12
|
# Micro::Struct.new(:first_name, :last_name, ...)
|
13
13
|
#
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: u-struct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Serradura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: '0'
|
88
88
|
requirements: []
|
89
|
-
rubygems_version: 3.2.
|
89
|
+
rubygems_version: 3.2.17
|
90
90
|
signing_key:
|
91
91
|
specification_version: 4
|
92
92
|
summary: Create powered Ruby structs.
|