immutable_struct_ex 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +2 -2
- data/README.md +22 -7
- data/lib/immutable_struct_ex/version.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: aa4a48dbdce57780e5b5d4070af7cc8c23178bfce3ad7fe7aa7f4ccb5c8c57bd
|
4
|
+
data.tar.gz: '093d4b2a568379b9f3a60c408e8b193c3529b08747a187a0c89740e3b5d18d10'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c0ac39ffb5460f9d7a02495758285d2cb6407d985f8bb1c52eff686e5e015bc3a28e5bc33a7a091507cb93a40348eebebe563cc6aaf49d0d65b7e54f6b33c2d
|
7
|
+
data.tar.gz: e3bbb35209074a059fd695aec4da31d60731929633c88e268bb643bdd0fd433530cb3f44bb57377e478a571cfaeae5a87cad0fd44084b2bb94b11270f50c4ac2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
### 0.3.0
|
2
|
+
* Changes
|
3
|
+
* Update README.md file with the correct gem name.
|
4
|
+
|
5
|
+
### 0.2.3
|
6
|
+
* Bug fix
|
7
|
+
* Fix bug in specs that failed to add criteria for passing tests (e.g. ".to eq true/false") so tests could not fail.
|
8
|
+
|
1
9
|
### 0.2.2
|
2
10
|
* Changes
|
3
11
|
* Restructure modules under lib/immutable_structure_ex folder.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -8,9 +8,9 @@
|
|
8
8
|
|
9
9
|
[](#license)
|
10
10
|
|
11
|
-
#
|
11
|
+
# immutable_struct_ex
|
12
12
|
|
13
|
-
|
13
|
+
immutable_struct_ex is yet another immutable struct. What makes immutable_struct_ex different, is that it allows you to create immutable structs in one step _by default_. In other words, other immutable struct gems force you to first define the struct, then instantiate the struct object; or, define the struct and instantiate the struct object via chaining. For example:
|
14
14
|
|
15
15
|
## Other Immutable Structs
|
16
16
|
|
@@ -24,31 +24,38 @@ some_immutable_struct = SomeImmutableStruct.new(:first, :last, :phone)
|
|
24
24
|
.new(first: 'John', last: 'Doe', phone: '(201) 230-7281')
|
25
25
|
```
|
26
26
|
|
27
|
-
##
|
28
|
-
|
27
|
+
## immutable_struct_ex
|
28
|
+
immutable_struct_ex allows you to instantiate and initialize the object _in one step:_
|
29
29
|
|
30
30
|
```ruby
|
31
31
|
immutable_struct_ex = ImmutableStructEx.new(first: 'John', last: 'Doe', phone: '(201) 230-7281')
|
32
|
+
|
32
33
|
immutable_struct_ex.first
|
33
34
|
#=> 'John'
|
35
|
+
|
34
36
|
immutable_struct_ex[:first]
|
35
37
|
#=> 'John'
|
38
|
+
|
36
39
|
immutable_struct_ex.last
|
37
40
|
#=> 'Doe'
|
41
|
+
|
38
42
|
immutable_struct_ex.phone
|
39
43
|
#=> '(201) 230-7281'
|
40
44
|
```
|
41
45
|
### Immutable
|
42
|
-
Like other immutable structs,
|
46
|
+
Like other immutable structs, immutable_struct_ex also removes methods that change the state of the object, making it _immutable:_
|
47
|
+
|
43
48
|
```ruby
|
44
49
|
immutable_struct_ex.first = 'Joe'
|
45
50
|
#=> NoMethodError: undefined method `first='...
|
51
|
+
|
46
52
|
immutable_struct_ex[:first] = 'Joe'
|
47
53
|
#=> NoMethodError: undefined method `[]='...
|
48
54
|
```
|
49
55
|
|
50
56
|
### Blocks
|
51
|
-
Also, not unlike other immutable structs,
|
57
|
+
Also, not unlike other immutable structs, immutable_struct_ex also allows you to pass a block:
|
58
|
+
|
52
59
|
```ruby
|
53
60
|
# With a block
|
54
61
|
immutable_struct_ex = ImmutableStructEx.new(first: 'John', last: 'Doe', phone: '(201) 230-7281') do
|
@@ -56,14 +63,22 @@ immutable_struct_ex = ImmutableStructEx.new(first: 'John', last: 'Doe', phone: '
|
|
56
63
|
first == 'John'
|
57
64
|
end
|
58
65
|
end
|
66
|
+
|
59
67
|
immutable_struct_ex.john?
|
60
68
|
#=> true
|
61
69
|
```
|
62
70
|
|
63
71
|
### Other Examples
|
72
|
+
Get creative. Below is an example of an immutable struct that provides _redaction_:
|
73
|
+
|
64
74
|
```ruby
|
65
75
|
# Redactable, immutable struct
|
66
|
-
user = {
|
76
|
+
user = {
|
77
|
+
username: 'jdoe',
|
78
|
+
password: 'p@55w0rD',
|
79
|
+
ssn: '123-70-9182'
|
80
|
+
}
|
81
|
+
|
67
82
|
immutable_struct_ex = ImmutableStructEx.new(**user) do
|
68
83
|
REDACT = %i(password ssn).freeze
|
69
84
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: immutable_struct_ex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gene M. Angelo, Jr.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -212,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
212
|
- !ruby/object:Gem::Version
|
213
213
|
version: '0'
|
214
214
|
requirements: []
|
215
|
-
rubygems_version: 3.
|
215
|
+
rubygems_version: 3.3.22
|
216
216
|
signing_key:
|
217
217
|
specification_version: 4
|
218
218
|
summary: Creates an immutable struct in one step.
|