ez_attributes 0.2.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55d1858c632570b78182239f11dd266098839e2035ba2279b88981188db1bf09
4
- data.tar.gz: 419e205ed30e874089e91910bc5478a592007864742a7852a0355347026efed9
3
+ metadata.gz: 73a1b5bf537a990b37264627c3464da95d92bc8900a89105dd88063b5d9f67e1
4
+ data.tar.gz: 0ae691b65597c06ed2aba85b247057d815ee864442f5d4418a586fdf565de622
5
5
  SHA512:
6
- metadata.gz: 24d2131f2609b1246ec5ca12fca605f9d37e0c73159882842e164549226f90440e8c0138fb767b943d9ed8f865a5eaf64a77714675a7ecdd622dcbb55a521f0e
7
- data.tar.gz: bc9779ed2588b57a8655003f888ebf3f055900afb719f395b578a7fa658423397a83213bac742142f0513c87358d22cd5752fbf287dd1308eff4b7c844d81e1f
6
+ metadata.gz: fe6b0fa0de7361ec94b8a5e54cbb302f9982da3dd0d25377744dfa8a48c0a7a6333ee4d707e65c3dbd1cfe00479eb4fe23e56d426dbdaf962d4d860b56395e8b
7
+ data.tar.gz: 5562e4cf1683ddaf6606fb831ba7715af417ce79b55d5cea6c7b7211c59ca5d3e1a4ce39978b06214d0b07a9832bc2eef6bf9162f3b159f67aa3c49d1286c54b
@@ -11,7 +11,7 @@ jobs:
11
11
  runs-on: ubuntu-latest
12
12
  strategy:
13
13
  matrix:
14
- ruby: [2.5, 2.6, 2.7, '3.0']
14
+ ruby: [3.2, 3.3, 3.4]
15
15
 
16
16
  steps:
17
17
  - uses: actions/checkout@v2
@@ -24,5 +24,5 @@ jobs:
24
24
  gem install bundler
25
25
  bundle install --jobs 4 --retry 3
26
26
  bundle exec rake
27
- - name: Rubocop Linter Action
28
- run: bundle exec rubocop --parallel
27
+ - name: Linter Action
28
+ run: bundle exec standardrb
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.8
1
+ 3.2.8
data/.standard.yml ADDED
@@ -0,0 +1 @@
1
+ format: progress
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.2.8
data/CHANGELOG.md CHANGED
@@ -7,8 +7,46 @@ 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
+
29
+ ## [0.3.0] - 2021-10-25
30
+
10
31
  <!-- ### Added -->
11
- <!-- ### Changed -->
32
+
33
+ ### Changed
34
+
35
+ - Allow configuring EzAttributes (PR #3)
36
+
37
+ ```ruby
38
+ class User
39
+ extend EzAttributes.configure(getters: false)
40
+
41
+ attributes :name, :age, email: 'guest@user.com'
42
+ end
43
+
44
+ User.new(name: 'Matz', age: 22).name
45
+ # NoMethodError (undefined method `name' for #<User:0x000055bac152f130>)
46
+ ```
47
+
48
+ - Replace Rubocop with StandardRB
49
+
12
50
  <!-- ### Removed -->
13
51
 
14
52
  ## [0.2.2] - 2021-04-30
@@ -45,7 +83,8 @@ end
45
83
 
46
84
  - Basic module to define class initializers with keyword args.
47
85
 
48
- [unreleased]: https://github.com/MatheusRich/ez_attributes/compare/v0.2.2...HEAD
86
+ [unreleased]: https://github.com/MatheusRich/ez_attributes/compare/v0.3.0...HEAD
87
+ [0.3.0]: https://github.com/MatheusRich/ez_attributes/releases/tag/v0.3.0
49
88
  [0.2.2]: https://github.com/MatheusRich/ez_attributes/releases/tag/v0.2.2
50
89
  [0.2.1]: https://github.com/MatheusRich/ez_attributes/releases/tag/v0.2.1
51
90
  [0.2.0]: https://github.com/MatheusRich/ez_attributes/releases/tag/v0.2.0
data/Gemfile CHANGED
@@ -1,21 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in f_service.gemspec
6
6
  gemspec
7
7
 
8
- gem 'rake', '~> 13.0.0'
9
- gem 'rubocop', require: false
10
- gem 'rubocop-performance', require: false
11
- gem 'rubocop-rspec', require: false
12
- gem 'solargraph'
8
+ gem "rake", "~> 13.0.0"
9
+ gem "standard"
13
10
 
14
11
  group :docs do
15
- gem 'yard'
12
+ gem "yard"
16
13
  end
17
14
 
18
15
  group :test do
19
- gem 'rspec', '~> 3.0'
20
- gem 'simplecov', require: false
16
+ gem "rspec", "~> 3.0"
17
+ gem "simplecov", require: false
21
18
  end
data/Gemfile.lock CHANGED
@@ -1,78 +1,76 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ez_attributes (0.2.2)
4
+ ez_attributes (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- ast (2.4.1)
10
- backport (1.1.2)
11
- benchmark (0.1.0)
12
- diff-lcs (1.4.4)
13
- docile (1.3.2)
14
- e2mmap (0.1.0)
15
- jaro_winkler (1.5.4)
16
- maruku (0.7.3)
17
- mini_portile2 (2.4.0)
18
- nokogiri (1.10.10)
19
- mini_portile2 (~> 2.4.0)
20
- parallel (1.20.1)
21
- parser (2.7.2.0)
9
+ ast (2.4.2)
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
- rainbow (3.0.0)
24
- rake (13.0.1)
25
- reverse_markdown (2.0.0)
26
- nokogiri
27
- rexml (3.2.4)
28
- rspec (3.10.0)
29
- rspec-core (~> 3.10.0)
30
- rspec-expectations (~> 3.10.0)
31
- rspec-mocks (~> 3.10.0)
32
- rspec-core (3.10.0)
33
- rspec-support (~> 3.10.0)
34
- 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)
35
30
  diff-lcs (>= 1.2.0, < 2.0)
36
- rspec-support (~> 3.10.0)
37
- rspec-mocks (3.10.0)
31
+ rspec-support (~> 3.12.0)
32
+ rspec-mocks (3.12.6)
38
33
  diff-lcs (>= 1.2.0, < 2.0)
39
- rspec-support (~> 3.10.0)
40
- rspec-support (3.10.0)
41
- rubocop (0.82.0)
42
- jaro_winkler (~> 1.5.1)
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 (>= 2.7.0.1)
40
+ parser (>= 3.3.0.2)
45
41
  rainbow (>= 2.2.2, < 4.0)
46
- rexml
42
+ regexp_parser (>= 2.9.3, < 3.0)
43
+ rubocop-ast (>= 1.36.2, < 2.0)
47
44
  ruby-progressbar (~> 1.7)
48
- unicode-display_width (>= 1.4.0, < 2.0)
49
- rubocop-performance (1.7.1)
50
- rubocop (>= 0.82.0)
51
- rubocop-rspec (1.41.0)
52
- rubocop (>= 0.68.1)
53
- ruby-progressbar (1.10.1)
54
- simplecov (0.19.1)
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)
55
53
  docile (~> 1.1)
56
54
  simplecov-html (~> 0.11)
55
+ simplecov_json_formatter (~> 0.1)
57
56
  simplecov-html (0.12.3)
58
- solargraph (0.39.17)
59
- backport (~> 1.1)
60
- benchmark
61
- bundler (>= 1.17.2)
62
- e2mmap
63
- jaro_winkler (~> 1.5)
64
- maruku (~> 0.7, >= 0.7.3)
65
- nokogiri (~> 1.9, >= 1.9.1)
66
- parser (~> 2.3)
67
- reverse_markdown (>= 1.0.5, < 3)
68
- rubocop (~> 0.52)
69
- thor (~> 1.0)
70
- tilt (~> 2.0)
71
- yard (~> 0.9, >= 0.9.24)
72
- thor (1.0.1)
73
- tilt (2.0.10)
74
- unicode-display_width (1.7.0)
75
- 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)
76
74
 
77
75
  PLATFORMS
78
76
  ruby
@@ -81,12 +79,9 @@ DEPENDENCIES
81
79
  ez_attributes!
82
80
  rake (~> 13.0.0)
83
81
  rspec (~> 3.0)
84
- rubocop
85
- rubocop-performance
86
- rubocop-rspec
87
82
  simplecov
88
- solargraph
83
+ standard
89
84
  yard
90
85
 
91
86
  BUNDLED WITH
92
- 2.2.6
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
 
@@ -58,16 +58,57 @@ user.name
58
58
  # => "Matz"
59
59
  ```
60
60
 
61
+ ### Configuration
62
+
63
+ You can disable getters:
64
+
65
+ ```ruby
66
+ class User
67
+ extend EzAttributes.configure(getters: false)
68
+
69
+ attributes :name, :age, email: 'guest@user.com'
70
+ end
71
+
72
+ u = User.new(name: 'Matz', age: 22)
73
+ # => #<User:0x000055bac152f130 @name="Matz", @age=22, @email="guest@user.com">
74
+
75
+ u.name
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)
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"
92
+ ```
93
+
61
94
  ## Development
62
95
 
63
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
96
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
97
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
98
+ prompt that will allow you to experiment.
64
99
 
65
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
100
+ To install this gem onto your local machine, run `bundle exec rake install`. To
101
+ release a new version, update the version number in `version.rb`, and then run
102
+ `bundle exec rake release`, which will create a git tag for the version, push
103
+ git commits and tags, and push the `.gem` file to
104
+ [rubygems.org](https://rubygems.org).
66
105
 
67
106
  ## Contributing
68
107
 
69
- Bug reports and pull requests are welcome on GitHub at https://github.com/MatheusRich/ez_attributes.
108
+ Bug reports and pull requests are welcome on GitHub at
109
+ https://github.com/MatheusRich/ez_attributes.
70
110
 
71
111
  ## License
72
112
 
73
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
113
+ The gem is available as open source under the terms of the [MIT
114
+ License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
@@ -1,29 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'lib/ez_attributes'
3
+ require_relative "lib/ez_attributes"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = 'ez_attributes'
7
- spec.version = EzAttributes::VERSION
8
- spec.authors = ['Matheus Richard']
9
- spec.email = ['matheusrichardt@gmail.com']
6
+ spec.name = "ez_attributes"
7
+ spec.version = EzAttributes::VERSION
8
+ spec.authors = ["Matheus Richard"]
9
+ spec.email = ["matheusrichardt@gmail.com"]
10
10
 
11
- spec.summary = 'Easily define initializers with keyword args.'
12
- spec.description = 'Easily define initializers with keyword args. It supports required and optional args.'
13
- spec.homepage = 'https://github.com/MatheusRich/ez_attributes.git'
14
- spec.license = 'MIT'
15
- spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
11
+ spec.summary = "Easily define initializers with keyword args."
12
+ spec.description = "Easily define initializers with keyword args. It supports required and optional args."
13
+ spec.homepage = "https://github.com/MatheusRich/ez_attributes.git"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.2.0")
16
16
 
17
- spec.metadata['homepage_uri'] = spec.homepage
18
- spec.metadata['source_code_uri'] = spec.homepage
19
- spec.metadata['changelog_uri'] = 'https://github.com/MatheusRich/ez_attributes/blob/main/CHANGELOG.md'
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = "https://github.com/MatheusRich/ez_attributes/blob/main/CHANGELOG.md"
20
20
 
21
21
  # Specify which files should be added to the gem when it is released.
22
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
23
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
24
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
25
  end
26
- spec.bindir = 'exe'
27
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
- spec.require_paths = ['lib']
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
29
  end
data/lib/ez_attributes.rb CHANGED
@@ -15,32 +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.2.2'
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
- # Defines multiple keyword arguments for a class initializer
24
- def attributes(*args, **args_with_default)
25
- required_args = args.map { |name| "#{name}:" }
26
- optional_args = args_with_default.map { |name, _| "#{name}: __args_with_default[:#{name}]" }
27
- init_args = (required_args + optional_args).join(', ')
23
+ def self.extended(other)
24
+ other.extend configure
25
+ end
26
+
27
+ def self.configure(getters: true, setters: false)
28
+ Module.new do
29
+ # Defines multiple keyword arguments for a class initializer
30
+ define_method :attributes do |*args, **args_with_default|
31
+ required_args = args.map { |name| "#{name}:" }
32
+ optional_args = args_with_default.map { |name, _| "#{name}: __args_with_default[:#{name}]" }
33
+ init_args = (required_args + optional_args).join(", ")
28
34
 
29
- define_method('__args_with_default', -> { Marshal.load(Marshal.dump(args_with_default)) })
30
- private :__args_with_default
35
+ define_method(:__args_with_default, -> { Marshal.load(Marshal.dump(args_with_default)) })
36
+ private :__args_with_default
31
37
 
32
- all_args = args + args_with_default.keys
33
- attr_reader(*(all_args - EXCEPTIONS))
38
+ all_args = args + args_with_default.keys
39
+ attr_reader(*(all_args - EXCEPTIONS)) if getters
40
+ attr_writer(*(all_args - EXCEPTIONS)) if setters
34
41
 
35
- class_eval <<~RUBY, __FILE__, __LINE__ + 1
36
- def initialize(#{init_args})
37
- #{all_args.map { |name| "@#{name} = binding.local_variable_get(:#{name})" }.join('; ')}
42
+ class_eval <<~CODE, __FILE__, __LINE__ + 1
43
+ def initialize(#{init_args})
44
+ #{all_args.map { |name| "@#{name} = binding.local_variable_get(:#{name})" }.join("; ")}
45
+ end
46
+ CODE
38
47
  end
39
- RUBY
40
- end
41
48
 
42
- # Defines a single keyword argument for a class initializer
43
- def attribute(name)
44
- attributes(name)
49
+ # Defines a single keyword argument for a class initializer
50
+ alias_method :attribute, :attributes
51
+ end
45
52
  end
46
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.2.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matheus Richard
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-30 00:00:00.000000000 Z
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.
@@ -21,8 +21,9 @@ files:
21
21
  - ".github/workflows/tests-and-linter.yml"
22
22
  - ".gitignore"
23
23
  - ".rspec"
24
- - ".rubocop.yml"
25
24
  - ".ruby-version"
25
+ - ".standard.yml"
26
+ - ".tool-versions"
26
27
  - CHANGELOG.md
27
28
  - Gemfile
28
29
  - Gemfile.lock
@@ -40,7 +41,7 @@ metadata:
40
41
  homepage_uri: https://github.com/MatheusRich/ez_attributes.git
41
42
  source_code_uri: https://github.com/MatheusRich/ez_attributes.git
42
43
  changelog_uri: https://github.com/MatheusRich/ez_attributes/blob/main/CHANGELOG.md
43
- post_install_message:
44
+ post_install_message:
44
45
  rdoc_options: []
45
46
  require_paths:
46
47
  - lib
@@ -48,16 +49,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
49
  requirements:
49
50
  - - ">="
50
51
  - !ruby/object:Gem::Version
51
- version: 2.5.0
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
- rubyforge_project:
59
- rubygems_version: 2.7.6.2
60
- signing_key:
59
+ rubygems_version: 3.4.19
60
+ signing_key:
61
61
  specification_version: 4
62
62
  summary: Easily define initializers with keyword args.
63
63
  test_files: []
data/.rubocop.yml DELETED
@@ -1,22 +0,0 @@
1
- require:
2
- - rubocop-rspec
3
- - rubocop-performance
4
-
5
- AllCops:
6
- NewCops: enable
7
-
8
- Layout/LineLength:
9
- Max: 120
10
-
11
- Metrics/BlockLength:
12
- Exclude:
13
- - "spec/**/*"
14
-
15
- Metrics/AbcSize:
16
- Enabled: false
17
-
18
- Style/DocumentationMethod:
19
- Enabled: true
20
-
21
- RSpec/ExampleLength:
22
- Max: 15