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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4b40b69da026b0f45f5514a8d340effc8f7d81489c4f1217237c16641186357
4
- data.tar.gz: 6a5cd7b12d2d1b16830a805b9904e5c212c685d5a32108439e8f9f2b8235dfb8
3
+ metadata.gz: bebaeb99b56b26288a87f8907532e194a4388563a11ed486c90d203c34d9e951
4
+ data.tar.gz: 66d1f615dcaa99c713d24b7ea375f00293396fe91d2314be223a487cfa90caa8
5
5
  SHA512:
6
- metadata.gz: 159075d6944696849893dd4f4860613b104b12f3e872c0cac65df62055af61309d9f9256a949693a01df7fb5b514e916755bf0f6f1295874d93b9bc1abb2a2b3
7
- data.tar.gz: 12db20998fcd5b1688e4786766630cee699daffacfca72d18e3e769ac387931dd310a46ff511862c7d9d9f2a458ae8667dd3e7623dbfca55802caa41fd3cfbb8
6
+ metadata.gz: 4131a340a7a5981a60a177a2a1c59846f12693053eb80cd77e289e83a3602e10df31b694c8bb8a0fbb9a8d60886ce4b0e27424cce27a1ae2e513570d981c0c67
7
+ data.tar.gz: 2ed2f7a1a80265ace687639e575f5395f3cb1c663ac0c4b5dc044a52a2ba321540942523a6a7f0b9377df6d2a4569e029b35a8f1345e861ab23cd0f5cd0d885b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.8.0] - 2021-12-05
4
+
5
+ - To-do
6
+
3
7
  ## [0.7.0] - 2021-12-04
4
8
 
5
9
  - To-do
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- u-struct (0.7.0)
4
+ u-struct (0.8.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -17,6 +17,7 @@ GEM
17
17
  simplecov_json_formatter (0.1.3)
18
18
 
19
19
  PLATFORMS
20
+ ruby
20
21
  x86_64-darwin-19
21
22
 
22
23
  DEPENDENCIES
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
- def_initialize_and_members(container, required_members, optional_members)
11
-
12
- def_to_proc(container) if features[:to_proc]
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 def_initialize_and_members(container, required_members, optional_members)
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
- # 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
- 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 def_to_proc(container)
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
- def self.to_proc
43
- ->(hash) { new(**hash) }
44
- end
57
+ def self.to_proc
58
+ ->(hash) { new(**hash) }
59
+ end
45
60
  RUBY
46
61
  end
47
62
  end
@@ -7,8 +7,7 @@ module Micro::Struct
7
7
  to_hash: false,
8
8
  to_proc: false,
9
9
  readonly: false,
10
- instance_copy: false
11
- }.freeze
10
+ instance_copy: false }.freeze
12
11
 
13
12
  Check = ->(to_ary:, to_hash:, to_proc:, readonly:, instance_copy:) do
14
13
  { to_ary: to_ary,
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Micro
4
4
  module Struct
5
- VERSION = '0.7.0'
5
+ VERSION = '0.8.0'
6
6
  end
7
7
  end
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.7.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-04 00:00:00.000000000 Z
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.21
89
+ rubygems_version: 3.2.17
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: Create powered Ruby structs.