ez_attributes 0.3.0 → 0.4.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/.github/workflows/tests-and-linter.yml +1 -1
- data/.ruby-version +1 -1
- data/.tool-versions +1 -0
- data/CHANGELOG.md +19 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +57 -66
- data/README.md +15 -1
- data/ez_attributes.gemspec +1 -1
- data/lib/ez_attributes.rb +9 -14
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73a1b5bf537a990b37264627c3464da95d92bc8900a89105dd88063b5d9f67e1
|
4
|
+
data.tar.gz: 0ae691b65597c06ed2aba85b247057d815ee864442f5d4418a586fdf565de622
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe6b0fa0de7361ec94b8a5e54cbb302f9982da3dd0d25377744dfa8a48c0a7a6333ee4d707e65c3dbd1cfe00479eb4fe23e56d426dbdaf962d4d860b56395e8b
|
7
|
+
data.tar.gz: 5562e4cf1683ddaf6606fb831ba7715af417ce79b55d5cea6c7b7211c59ca5d3e1a4ce39978b06214d0b07a9832bc2eef6bf9162f3b159f67aa3c49d1286c54b
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
3.2.8
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.2.8
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.4.0] - 2025-05-23
|
11
|
+
|
12
|
+
- Drop support for ruby <= 3.1
|
13
|
+
- [BUGFIX] - Single attribute with default value breaking on Ruby 3 (#4)
|
14
|
+
- Allow defining setters via configuration
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
class User
|
18
|
+
extend EzAttributes.configure(setters: true)
|
19
|
+
|
20
|
+
attributes :name, :age, email: 'guest@user.com'
|
21
|
+
end
|
22
|
+
|
23
|
+
user = User.new(name: 'Matz', age: 22)
|
24
|
+
user.name = 'Yukihiro Matsumoto'
|
25
|
+
user.name
|
26
|
+
# => "Yukihiro Matsumoto"
|
27
|
+
```
|
28
|
+
|
10
29
|
## [0.3.0] - 2021-10-25
|
11
30
|
|
12
31
|
<!-- ### Added -->
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,84 +1,76 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ez_attributes (0.
|
4
|
+
ez_attributes (0.4.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.4.2)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
mini_portile2 (2.4.0)
|
18
|
-
nokogiri (1.10.10)
|
19
|
-
mini_portile2 (~> 2.4.0)
|
20
|
-
parallel (1.21.0)
|
21
|
-
parser (2.7.2.0)
|
10
|
+
diff-lcs (1.5.0)
|
11
|
+
docile (1.4.0)
|
12
|
+
json (2.9.1)
|
13
|
+
language_server-protocol (3.17.0.3)
|
14
|
+
lint_roller (1.1.0)
|
15
|
+
parallel (1.26.3)
|
16
|
+
parser (3.3.6.0)
|
22
17
|
ast (~> 2.4.1)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
rspec-
|
31
|
-
rspec-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
rspec-expectations (3.10.0)
|
18
|
+
racc
|
19
|
+
racc (1.8.1)
|
20
|
+
rainbow (3.1.1)
|
21
|
+
rake (13.0.6)
|
22
|
+
regexp_parser (2.10.0)
|
23
|
+
rspec (3.12.0)
|
24
|
+
rspec-core (~> 3.12.0)
|
25
|
+
rspec-expectations (~> 3.12.0)
|
26
|
+
rspec-mocks (~> 3.12.0)
|
27
|
+
rspec-core (3.12.2)
|
28
|
+
rspec-support (~> 3.12.0)
|
29
|
+
rspec-expectations (3.12.3)
|
36
30
|
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
-
rspec-support (~> 3.
|
38
|
-
rspec-mocks (3.
|
31
|
+
rspec-support (~> 3.12.0)
|
32
|
+
rspec-mocks (3.12.6)
|
39
33
|
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
-
rspec-support (~> 3.
|
41
|
-
rspec-support (3.
|
42
|
-
rubocop (
|
34
|
+
rspec-support (~> 3.12.0)
|
35
|
+
rspec-support (3.12.1)
|
36
|
+
rubocop (1.69.2)
|
37
|
+
json (~> 2.3)
|
38
|
+
language_server-protocol (>= 3.17.0)
|
43
39
|
parallel (~> 1.10)
|
44
|
-
parser (>=
|
40
|
+
parser (>= 3.3.0.2)
|
45
41
|
rainbow (>= 2.2.2, < 4.0)
|
46
|
-
regexp_parser (>=
|
47
|
-
|
48
|
-
rubocop-ast (>= 0.5.0)
|
42
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
43
|
+
rubocop-ast (>= 1.36.2, < 2.0)
|
49
44
|
ruby-progressbar (~> 1.7)
|
50
|
-
unicode-display_width (>=
|
51
|
-
rubocop-ast (1.
|
52
|
-
parser (>=
|
53
|
-
rubocop-performance (1.
|
54
|
-
rubocop (>=
|
55
|
-
rubocop-ast (>=
|
56
|
-
ruby-progressbar (1.
|
57
|
-
simplecov (0.
|
45
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
46
|
+
rubocop-ast (1.37.0)
|
47
|
+
parser (>= 3.3.1.0)
|
48
|
+
rubocop-performance (1.23.0)
|
49
|
+
rubocop (>= 1.48.1, < 2.0)
|
50
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
51
|
+
ruby-progressbar (1.13.0)
|
52
|
+
simplecov (0.22.0)
|
58
53
|
docile (~> 1.1)
|
59
54
|
simplecov-html (~> 0.11)
|
55
|
+
simplecov_json_formatter (~> 0.1)
|
60
56
|
simplecov-html (0.12.3)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
thor (1.0.1)
|
79
|
-
tilt (2.0.10)
|
80
|
-
unicode-display_width (1.8.0)
|
81
|
-
yard (0.9.25)
|
57
|
+
simplecov_json_formatter (0.1.4)
|
58
|
+
standard (1.43.0)
|
59
|
+
language_server-protocol (~> 3.17.0.2)
|
60
|
+
lint_roller (~> 1.0)
|
61
|
+
rubocop (~> 1.69.1)
|
62
|
+
standard-custom (~> 1.0.0)
|
63
|
+
standard-performance (~> 1.6)
|
64
|
+
standard-custom (1.0.2)
|
65
|
+
lint_roller (~> 1.0)
|
66
|
+
rubocop (~> 1.50)
|
67
|
+
standard-performance (1.6.0)
|
68
|
+
lint_roller (~> 1.1)
|
69
|
+
rubocop-performance (~> 1.23.0)
|
70
|
+
unicode-display_width (3.1.3)
|
71
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
72
|
+
unicode-emoji (4.0.4)
|
73
|
+
yard (0.9.34)
|
82
74
|
|
83
75
|
PLATFORMS
|
84
76
|
ruby
|
@@ -88,9 +80,8 @@ DEPENDENCIES
|
|
88
80
|
rake (~> 13.0.0)
|
89
81
|
rspec (~> 3.0)
|
90
82
|
simplecov
|
91
|
-
solargraph
|
92
83
|
standard
|
93
84
|
yard
|
94
85
|
|
95
86
|
BUNDLED WITH
|
96
|
-
2.
|
87
|
+
2.3.9
|
data/README.md
CHANGED
@@ -46,7 +46,7 @@ Then, add the required and optional fields
|
|
46
46
|
class User
|
47
47
|
extend EzAttributes
|
48
48
|
|
49
|
-
# Here name and age are required, and email has a default value, so it is optional.
|
49
|
+
# Here, `name` and `age` are required, and `email` has a default value, so it is optional.
|
50
50
|
attributes :name, :age, email: 'guest@user.com'
|
51
51
|
end
|
52
52
|
|
@@ -74,7 +74,21 @@ u = User.new(name: 'Matz', age: 22)
|
|
74
74
|
|
75
75
|
u.name
|
76
76
|
# NoMethodError (undefined method `name' for #<User:0x000055bac152f130>)
|
77
|
+
```
|
78
|
+
|
79
|
+
You can enable setters:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
class User
|
83
|
+
extend EzAttributes.configure(setters: true)
|
77
84
|
|
85
|
+
attributes :name, :age, email: 'guest@user.com'
|
86
|
+
end
|
87
|
+
|
88
|
+
user = User.new(name: 'Matz', age: 22)
|
89
|
+
user.name = 'Yukihiro Matsumoto'
|
90
|
+
user.name
|
91
|
+
# => "Yukihiro Matsumoto"
|
78
92
|
```
|
79
93
|
|
80
94
|
## Development
|
data/ez_attributes.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = "Easily define initializers with keyword args. It supports required and optional args."
|
13
13
|
spec.homepage = "https://github.com/MatheusRich/ez_attributes.git"
|
14
14
|
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.2.0")
|
16
16
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
18
18
|
spec.metadata["source_code_uri"] = spec.homepage
|
data/lib/ez_attributes.rb
CHANGED
@@ -15,44 +15,39 @@
|
|
15
15
|
# => #<User:0x000055bac152f130 @name="Matheus", @age=22, @email="guest@user.com">
|
16
16
|
module EzAttributes
|
17
17
|
# Gem version
|
18
|
-
VERSION = "0.
|
18
|
+
VERSION = "0.4.0"
|
19
19
|
|
20
|
-
# Attributes that won't have a getter to prevent conflicts with default methods
|
20
|
+
# Attributes that won't have a getter/setter to prevent conflicts with default methods
|
21
21
|
EXCEPTIONS = [:class].freeze
|
22
22
|
|
23
23
|
def self.extended(other)
|
24
24
|
other.extend configure
|
25
25
|
end
|
26
26
|
|
27
|
-
def self.configure(getters: true)
|
28
|
-
|
29
|
-
|
30
|
-
mod.module_eval do
|
27
|
+
def self.configure(getters: true, setters: false)
|
28
|
+
Module.new do
|
31
29
|
# Defines multiple keyword arguments for a class initializer
|
32
30
|
define_method :attributes do |*args, **args_with_default|
|
33
31
|
required_args = args.map { |name| "#{name}:" }
|
34
32
|
optional_args = args_with_default.map { |name, _| "#{name}: __args_with_default[:#{name}]" }
|
35
33
|
init_args = (required_args + optional_args).join(", ")
|
36
34
|
|
37
|
-
define_method(
|
35
|
+
define_method(:__args_with_default, -> { Marshal.load(Marshal.dump(args_with_default)) })
|
38
36
|
private :__args_with_default
|
39
37
|
|
40
38
|
all_args = args + args_with_default.keys
|
41
39
|
attr_reader(*(all_args - EXCEPTIONS)) if getters
|
40
|
+
attr_writer(*(all_args - EXCEPTIONS)) if setters
|
42
41
|
|
43
|
-
class_eval <<~
|
42
|
+
class_eval <<~CODE, __FILE__, __LINE__ + 1
|
44
43
|
def initialize(#{init_args})
|
45
44
|
#{all_args.map { |name| "@#{name} = binding.local_variable_get(:#{name})" }.join("; ")}
|
46
45
|
end
|
47
|
-
|
46
|
+
CODE
|
48
47
|
end
|
49
48
|
|
50
49
|
# Defines a single keyword argument for a class initializer
|
51
|
-
|
52
|
-
attributes(name)
|
53
|
-
end
|
50
|
+
alias_method :attribute, :attributes
|
54
51
|
end
|
55
|
-
|
56
|
-
mod
|
57
52
|
end
|
58
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ez_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matheus Richard
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Easily define initializers with keyword args. It supports required and
|
14
14
|
optional args.
|
@@ -23,6 +23,7 @@ files:
|
|
23
23
|
- ".rspec"
|
24
24
|
- ".ruby-version"
|
25
25
|
- ".standard.yml"
|
26
|
+
- ".tool-versions"
|
26
27
|
- CHANGELOG.md
|
27
28
|
- Gemfile
|
28
29
|
- Gemfile.lock
|
@@ -48,14 +49,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
49
|
requirements:
|
49
50
|
- - ">="
|
50
51
|
- !ruby/object:Gem::Version
|
51
|
-
version: 2.
|
52
|
+
version: 3.2.0
|
52
53
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
54
|
requirements:
|
54
55
|
- - ">="
|
55
56
|
- !ruby/object:Gem::Version
|
56
57
|
version: '0'
|
57
58
|
requirements: []
|
58
|
-
rubygems_version: 3.
|
59
|
+
rubygems_version: 3.4.19
|
59
60
|
signing_key:
|
60
61
|
specification_version: 4
|
61
62
|
summary: Easily define initializers with keyword args.
|