ez_attributes 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e1a1656644b5f4125ced596740a565eb787d9c55d9a355cf819f6064707edd3d
4
+ data.tar.gz: f4ac601d6787ac40cee85efbc1fafe3f8664fbf5fbf90efc53ba0a92652bd30e
5
+ SHA512:
6
+ metadata.gz: aedc2203f94400db3327994c3b568e3d2e419b61429dec040ccb4b7bf932ced79433e2c07db92ae2c75c223ac73198c8061e7da6754b91031cf45227a3ad864c
7
+ data.tar.gz: 81bc482c0f146b8e95a666e1bf2e4631eeaaa7b9ed18dd120b1a473ccf7796232ef24db28537b44c147ef1d27d97d3ff2ce3ba1bfc70c64b2607233398477521
@@ -0,0 +1,28 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby: [2.5, 2.6, 2.7]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - name: Set up Ruby ${{ matrix.ruby }}
19
+ uses: actions/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby }}
22
+ - name: Build and test with Rake
23
+ run: |
24
+ gem install bundler
25
+ bundle install --jobs 4 --retry 3
26
+ bundle exec rake
27
+ - name: Rubocop Linter Action
28
+ run: bundle exec rubocop --parallel
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,20 @@
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
+
@@ -0,0 +1 @@
1
+ 2.5.8
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ <!-- ### Added -->
11
+ <!-- ### Changed -->
12
+
13
+ ## <!-- ### Removed -->
14
+
15
+ ## [0.1.0] - 2020-11-24
16
+
17
+ ### Added
18
+
19
+ - Basic module to define class initializers with keyword args.
20
+
21
+ [unreleased]: https://github.com/MatheusRich/ez_attributes/compare/v0.1.0...HEAD
22
+ [0.1.0]: https://github.com/MatheusRich/ez_attributes/releases/tag/v0.1.0
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in f_service.gemspec
6
+ gemspec
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'
13
+
14
+ group :docs do
15
+ gem 'yard'
16
+ end
17
+
18
+ group :test do
19
+ gem 'rspec', '~> 3.0'
20
+ gem 'simplecov', require: false
21
+ end
@@ -0,0 +1,92 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ez_attributes (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
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)
22
+ 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)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.10.0)
37
+ rspec-mocks (3.10.0)
38
+ 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)
43
+ parallel (~> 1.10)
44
+ parser (>= 2.7.0.1)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ rexml
47
+ 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)
55
+ docile (~> 1.1)
56
+ simplecov-html (~> 0.11)
57
+ 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)
76
+
77
+ PLATFORMS
78
+ ruby
79
+
80
+ DEPENDENCIES
81
+ ez_attributes!
82
+ rake (~> 13.0.0)
83
+ rspec (~> 3.0)
84
+ rubocop
85
+ rubocop-performance
86
+ rubocop-rspec
87
+ simplecov
88
+ solargraph
89
+ yard
90
+
91
+ BUNDLED WITH
92
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Matheus Richard
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,73 @@
1
+ <p align="center">
2
+ <h1 align="center">EzAttributes</h1>
3
+
4
+ <p align="center">
5
+ <i>Easily define initializers with keyword args</i>
6
+ <br>
7
+ <br>
8
+ <img src="https://img.shields.io/gem/v/ez_attributes">
9
+ <img src="https://img.shields.io/gem/dt/ez_attributes">
10
+ <img src="https://github.com/MatheusRich/ez_attributes/workflows/Ruby/badge.svg">
11
+ <a href="https://github.com/MatheusRich/ez_attributes/blob/master/LICENSE">
12
+ <img src="https://img.shields.io/github/license/MatheusRich/ez_attributes.svg" alt="License">
13
+ </a>
14
+ </p>
15
+ </p>
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'ez_attributes'
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ $ bundle install
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install ez_attributes
32
+
33
+ ## Usage
34
+
35
+ The first step is to extend EzAttributes in your class.
36
+
37
+ ```ruby
38
+ class User
39
+ extend EzAttributes
40
+ end
41
+ ```
42
+
43
+ Then, add the required and optional fields
44
+
45
+ ```ruby
46
+ class User
47
+ extend EzAttributes
48
+
49
+ # Here name and age are required, and email has a default value, so it is optional.
50
+ attributes :name, :age, email: 'guest@user.com'
51
+ end
52
+
53
+ User.new(name: 'Matz', age: 22)
54
+ # => #<User:0x000055bac152f130 @name="Matz", @age=22, @email="guest@user.com">
55
+
56
+ # EzAttributes will add getters for all fields too.
57
+ User.name
58
+ # => "Matz"
59
+ ```
60
+
61
+ ## Development
62
+
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.
64
+
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).
66
+
67
+ ## Contributing
68
+
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/MatheusRich/ez_attributes.
70
+
71
+ ## License
72
+
73
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'ez_attributes'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/ez_attributes'
4
+
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']
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')
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'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Easily define initializers with keyword args.
4
+ # It supports required and optional args.
5
+ #
6
+ # @example
7
+ # class User
8
+ # extend EzAttributes
9
+ #
10
+ # # Here name and age are required, and email has a default value, so it is optional.
11
+ # attributes :name, :age, email: 'guest@user.com'
12
+ # end
13
+ #
14
+ # User.new(name: 'Matheus', age: 22)
15
+ # => #<User:0x000055bac152f130 @name="Matheus", @age=22, @email="guest@user.com">
16
+ module EzAttributes
17
+ # Gem version
18
+ VERSION = '0.1.0'
19
+
20
+ # Defines multiple keyword arguments for a class initializer
21
+ def attributes(*args, **args_with_default)
22
+ required_args = args.map { |name| "#{name}:" }
23
+ optional_args = args_with_default.map { |name, _| "#{name}: __args_with_default[:#{name}]" }
24
+ init_args = (required_args + optional_args).join(', ')
25
+
26
+ define_method('__args_with_default', -> { args_with_default.dup })
27
+ private :__args_with_default
28
+
29
+ all_args = args + args_with_default.keys
30
+ attr_reader(*all_args)
31
+
32
+ class_eval <<~RUBY, __FILE__, __LINE__ + 1
33
+ def initialize(#{init_args})
34
+ #{all_args.map { |name| "@#{name} = #{name}" }.join('; ')}
35
+ end
36
+ RUBY
37
+ end
38
+
39
+ # Defines a single keyword argument for a class initializer
40
+ def attribute(name)
41
+ attributes(name)
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ez_attributes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matheus Richard
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Easily define initializers with keyword args. It supports required and
14
+ optional args.
15
+ email:
16
+ - matheusrichardt@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".github/workflows/tests-and-linter.yml"
22
+ - ".gitignore"
23
+ - ".rspec"
24
+ - ".rubocop.yml"
25
+ - ".ruby-version"
26
+ - CHANGELOG.md
27
+ - Gemfile
28
+ - Gemfile.lock
29
+ - LICENSE.txt
30
+ - README.md
31
+ - Rakefile
32
+ - bin/console
33
+ - bin/setup
34
+ - ez_attributes.gemspec
35
+ - lib/ez_attributes.rb
36
+ homepage: https://github.com/MatheusRich/ez_attributes.git
37
+ licenses:
38
+ - MIT
39
+ metadata:
40
+ homepage_uri: https://github.com/MatheusRich/ez_attributes.git
41
+ source_code_uri: https://github.com/MatheusRich/ez_attributes.git
42
+ changelog_uri: https://github.com/MatheusRich/ez_attributes/blob/main/CHANGELOG.md
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 2.5.0
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.7.6.2
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Easily define initializers with keyword args.
63
+ test_files: []