ez_attributes 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests-and-linter.yml +2 -2
- data/.standard.yml +1 -0
- data/CHANGELOG.md +22 -2
- data/Gemfile +7 -9
- data/Gemfile.lock +21 -17
- data/README.md +31 -4
- data/Rakefile +2 -2
- data/ez_attributes.gemspec +16 -16
- data/lib/ez_attributes.rb +30 -18
- metadata +7 -8
- data/.rubocop.yml +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d004aaed015e6616f82058b5eb28d543be87d27a489ce9736bb558273405a4f
|
4
|
+
data.tar.gz: 5cda1cf13ae92c1b390987d5b92bd1f2c3cd5f72aab9380d206198d20cf137d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce17bb4e9bfc325c49af790b476e77110c42a1f67cefe663ac80c44cb4dd0e2e30f407292fb7c446b259fa46e89f836682ec39f1eafe8c3c9550b6f443fc28ec
|
7
|
+
data.tar.gz: 84e2e39b8c054f2a1dccfbfa0160c2f83786f1bf91b73784e065c00338887913e07aa59a934ce3f6c29e36d7cc640a5fee128c1f7cdb850edf71717ccb27370d
|
data/.standard.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
format: progress
|
data/CHANGELOG.md
CHANGED
@@ -7,8 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.3.0] - 2021-10-25
|
11
|
+
|
10
12
|
<!-- ### Added -->
|
11
|
-
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
|
16
|
+
- Allow configuring EzAttributes (PR #3)
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
class User
|
20
|
+
extend EzAttributes.configure(getters: false)
|
21
|
+
|
22
|
+
attributes :name, :age, email: 'guest@user.com'
|
23
|
+
end
|
24
|
+
|
25
|
+
User.new(name: 'Matz', age: 22).name
|
26
|
+
# NoMethodError (undefined method `name' for #<User:0x000055bac152f130>)
|
27
|
+
```
|
28
|
+
|
29
|
+
- Replace Rubocop with StandardRB
|
30
|
+
|
12
31
|
<!-- ### Removed -->
|
13
32
|
|
14
33
|
## [0.2.2] - 2021-04-30
|
@@ -45,7 +64,8 @@ end
|
|
45
64
|
|
46
65
|
- Basic module to define class initializers with keyword args.
|
47
66
|
|
48
|
-
[unreleased]: https://github.com/MatheusRich/ez_attributes/compare/v0.
|
67
|
+
[unreleased]: https://github.com/MatheusRich/ez_attributes/compare/v0.3.0...HEAD
|
68
|
+
[0.3.0]: https://github.com/MatheusRich/ez_attributes/releases/tag/v0.3.0
|
49
69
|
[0.2.2]: https://github.com/MatheusRich/ez_attributes/releases/tag/v0.2.2
|
50
70
|
[0.2.1]: https://github.com/MatheusRich/ez_attributes/releases/tag/v0.2.1
|
51
71
|
[0.2.0]: https://github.com/MatheusRich/ez_attributes/releases/tag/v0.2.0
|
data/Gemfile
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
source
|
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
|
9
|
-
gem
|
10
|
-
gem
|
11
|
-
gem 'rubocop-rspec', require: false
|
12
|
-
gem 'solargraph'
|
8
|
+
gem "rake", "~> 13.0.0"
|
9
|
+
gem "standard"
|
10
|
+
gem "solargraph"
|
13
11
|
|
14
12
|
group :docs do
|
15
|
-
gem
|
13
|
+
gem "yard"
|
16
14
|
end
|
17
15
|
|
18
16
|
group :test do
|
19
|
-
gem
|
20
|
-
gem
|
17
|
+
gem "rspec", "~> 3.0"
|
18
|
+
gem "simplecov", require: false
|
21
19
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ez_attributes (0.
|
4
|
+
ez_attributes (0.3.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
ast (2.4.
|
9
|
+
ast (2.4.2)
|
10
10
|
backport (1.1.2)
|
11
11
|
benchmark (0.1.0)
|
12
12
|
diff-lcs (1.4.4)
|
@@ -17,14 +17,15 @@ GEM
|
|
17
17
|
mini_portile2 (2.4.0)
|
18
18
|
nokogiri (1.10.10)
|
19
19
|
mini_portile2 (~> 2.4.0)
|
20
|
-
parallel (1.
|
20
|
+
parallel (1.21.0)
|
21
21
|
parser (2.7.2.0)
|
22
22
|
ast (~> 2.4.1)
|
23
23
|
rainbow (3.0.0)
|
24
24
|
rake (13.0.1)
|
25
|
+
regexp_parser (2.1.1)
|
25
26
|
reverse_markdown (2.0.0)
|
26
27
|
nokogiri
|
27
|
-
rexml (3.2.
|
28
|
+
rexml (3.2.5)
|
28
29
|
rspec (3.10.0)
|
29
30
|
rspec-core (~> 3.10.0)
|
30
31
|
rspec-expectations (~> 3.10.0)
|
@@ -38,19 +39,21 @@ GEM
|
|
38
39
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
40
|
rspec-support (~> 3.10.0)
|
40
41
|
rspec-support (3.10.0)
|
41
|
-
rubocop (0.
|
42
|
-
jaro_winkler (~> 1.5.1)
|
42
|
+
rubocop (0.92.0)
|
43
43
|
parallel (~> 1.10)
|
44
|
-
parser (>= 2.7.
|
44
|
+
parser (>= 2.7.1.5)
|
45
45
|
rainbow (>= 2.2.2, < 4.0)
|
46
|
+
regexp_parser (>= 1.7)
|
46
47
|
rexml
|
48
|
+
rubocop-ast (>= 0.5.0)
|
47
49
|
ruby-progressbar (~> 1.7)
|
48
50
|
unicode-display_width (>= 1.4.0, < 2.0)
|
49
|
-
rubocop-
|
50
|
-
|
51
|
-
rubocop-
|
52
|
-
rubocop (>= 0.
|
53
|
-
|
51
|
+
rubocop-ast (1.4.1)
|
52
|
+
parser (>= 2.7.1.5)
|
53
|
+
rubocop-performance (1.8.1)
|
54
|
+
rubocop (>= 0.87.0)
|
55
|
+
rubocop-ast (>= 0.4.0)
|
56
|
+
ruby-progressbar (1.11.0)
|
54
57
|
simplecov (0.19.1)
|
55
58
|
docile (~> 1.1)
|
56
59
|
simplecov-html (~> 0.11)
|
@@ -69,9 +72,12 @@ GEM
|
|
69
72
|
thor (~> 1.0)
|
70
73
|
tilt (~> 2.0)
|
71
74
|
yard (~> 0.9, >= 0.9.24)
|
75
|
+
standard (0.7)
|
76
|
+
rubocop (= 0.92)
|
77
|
+
rubocop-performance (= 1.8.1)
|
72
78
|
thor (1.0.1)
|
73
79
|
tilt (2.0.10)
|
74
|
-
unicode-display_width (1.
|
80
|
+
unicode-display_width (1.8.0)
|
75
81
|
yard (0.9.25)
|
76
82
|
|
77
83
|
PLATFORMS
|
@@ -81,12 +87,10 @@ DEPENDENCIES
|
|
81
87
|
ez_attributes!
|
82
88
|
rake (~> 13.0.0)
|
83
89
|
rspec (~> 3.0)
|
84
|
-
rubocop
|
85
|
-
rubocop-performance
|
86
|
-
rubocop-rspec
|
87
90
|
simplecov
|
88
91
|
solargraph
|
92
|
+
standard
|
89
93
|
yard
|
90
94
|
|
91
95
|
BUNDLED WITH
|
92
|
-
2.2.
|
96
|
+
2.2.29
|
data/README.md
CHANGED
@@ -58,16 +58,43 @@ 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
|
+
|
61
80
|
## Development
|
62
81
|
|
63
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
82
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
83
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
84
|
+
prompt that will allow you to experiment.
|
64
85
|
|
65
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To
|
86
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
87
|
+
release a new version, update the version number in `version.rb`, and then run
|
88
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
89
|
+
git commits and tags, and push the `.gem` file to
|
90
|
+
[rubygems.org](https://rubygems.org).
|
66
91
|
|
67
92
|
## Contributing
|
68
93
|
|
69
|
-
Bug reports and pull requests are welcome on GitHub at
|
94
|
+
Bug reports and pull requests are welcome on GitHub at
|
95
|
+
https://github.com/MatheusRich/ez_attributes.
|
70
96
|
|
71
97
|
## License
|
72
98
|
|
73
|
-
The gem is available as open source under the terms of the [MIT
|
99
|
+
The gem is available as open source under the terms of the [MIT
|
100
|
+
License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
data/ez_attributes.gemspec
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "lib/ez_attributes"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name
|
7
|
-
spec.version
|
8
|
-
spec.authors
|
9
|
-
spec.email
|
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
|
12
|
-
spec.description
|
13
|
-
spec.homepage
|
14
|
-
spec.license
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new(
|
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")
|
16
16
|
|
17
|
-
spec.metadata[
|
18
|
-
spec.metadata[
|
19
|
-
spec.metadata[
|
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
|
27
|
-
spec.executables
|
28
|
-
spec.require_paths = [
|
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,44 @@
|
|
15
15
|
# => #<User:0x000055bac152f130 @name="Matheus", @age=22, @email="guest@user.com">
|
16
16
|
module EzAttributes
|
17
17
|
# Gem version
|
18
|
-
VERSION =
|
18
|
+
VERSION = "0.3.0"
|
19
19
|
|
20
20
|
# Attributes that won't have a getter to prevent conflicts with default methods
|
21
21
|
EXCEPTIONS = [:class].freeze
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
def self.extended(other)
|
24
|
+
other.extend configure
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.configure(getters: true)
|
28
|
+
mod = Module.new
|
29
|
+
|
30
|
+
mod.module_eval do
|
31
|
+
# Defines multiple keyword arguments for a class initializer
|
32
|
+
define_method :attributes do |*args, **args_with_default|
|
33
|
+
required_args = args.map { |name| "#{name}:" }
|
34
|
+
optional_args = args_with_default.map { |name, _| "#{name}: __args_with_default[:#{name}]" }
|
35
|
+
init_args = (required_args + optional_args).join(", ")
|
28
36
|
|
29
|
-
|
30
|
-
|
37
|
+
define_method("__args_with_default", -> { Marshal.load(Marshal.dump(args_with_default)) })
|
38
|
+
private :__args_with_default
|
31
39
|
|
32
|
-
|
33
|
-
|
40
|
+
all_args = args + args_with_default.keys
|
41
|
+
attr_reader(*(all_args - EXCEPTIONS)) if getters
|
34
42
|
|
35
|
-
|
36
|
-
|
37
|
-
|
43
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
44
|
+
def initialize(#{init_args})
|
45
|
+
#{all_args.map { |name| "@#{name} = binding.local_variable_get(:#{name})" }.join("; ")}
|
46
|
+
end
|
47
|
+
RUBY
|
38
48
|
end
|
39
|
-
RUBY
|
40
|
-
end
|
41
49
|
|
42
|
-
|
43
|
-
|
44
|
-
|
50
|
+
# Defines a single keyword argument for a class initializer
|
51
|
+
define_method :attribute do |name|
|
52
|
+
attributes(name)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
mod
|
45
57
|
end
|
46
58
|
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.3.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-
|
11
|
+
date: 2021-10-25 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,8 @@ 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
26
|
- CHANGELOG.md
|
27
27
|
- Gemfile
|
28
28
|
- Gemfile.lock
|
@@ -40,7 +40,7 @@ metadata:
|
|
40
40
|
homepage_uri: https://github.com/MatheusRich/ez_attributes.git
|
41
41
|
source_code_uri: https://github.com/MatheusRich/ez_attributes.git
|
42
42
|
changelog_uri: https://github.com/MatheusRich/ez_attributes/blob/main/CHANGELOG.md
|
43
|
-
post_install_message:
|
43
|
+
post_install_message:
|
44
44
|
rdoc_options: []
|
45
45
|
require_paths:
|
46
46
|
- lib
|
@@ -55,9 +55,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '0'
|
57
57
|
requirements: []
|
58
|
-
|
59
|
-
|
60
|
-
signing_key:
|
58
|
+
rubygems_version: 3.2.25
|
59
|
+
signing_key:
|
61
60
|
specification_version: 4
|
62
61
|
summary: Easily define initializers with keyword args.
|
63
62
|
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
|