attr_extras 6.2.4 → 6.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +26 -0
- data/README.md +63 -7
- data/attr_extras.gemspec +1 -0
- data/lib/attr_extras/version.rb +1 -1
- metadata +6 -5
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a01c4bfc2a6ce3f1ae8735fe122b7abbd65c99be5a17330087e09e028e59b3cb
|
4
|
+
data.tar.gz: c83abb5d1467b7c91b2ff0c54220fa72ebdc2d6ee0deba2c7ca8edc3629f744c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48893855229adec5435cd0b709c50cf1e631e321197dd23baeaaa54e11c513f1d4f47ac3e9b3ab2268fc6d86c26c519e57c8e12d9c7aa2a7e819e9c5a53d9cfd
|
7
|
+
data.tar.gz: dc63a635eedac54ce49b25eece473e5264b655d2c87852725bc28baeaf4f9c7d516febad45978ba71816c3dec0afc1e5e114c9587c16ad890999a408efe588cd
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: Ruby CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby-version: ["3.0", "2.7", "2.6", "2.5", "jruby-head"]
|
17
|
+
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v2
|
20
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby-version }}
|
24
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
25
|
+
- name: Run tests
|
26
|
+
run: bundle exec rake
|
data/README.md
CHANGED
@@ -1,22 +1,31 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/attr_extras.svg)](https://badge.fury.io/rb/attr_extras)
|
2
|
-
[![
|
2
|
+
[![Ruby CI](https://github.com/barsoom/attr_extras/actions/workflows/ci.yml/badge.svg)](https://github.com/barsoom/attr_extras/actions/workflows/ci.yml)
|
3
3
|
[![Code Climate](https://codeclimate.com/github/barsoom/attr_extras/badges/gpa.svg)](https://codeclimate.com/github/barsoom/attr_extras)
|
4
4
|
|
5
5
|
# attr\_extras
|
6
6
|
|
7
7
|
Takes some boilerplate out of Ruby, lowering the barrier to extracting small focused classes, without [the downsides of using `Struct`](http://thepugautomatic.com/2013/08/struct-inheritance-is-overused/).
|
8
8
|
|
9
|
+
Provides lower-level methods like `attr_private` and `attr_value` that nicely complement Ruby's built-in `attr_accessor`, `attr_reader` and `attr_writer`.
|
10
|
+
|
11
|
+
Also higher-level ones like `pattr_initialize` (or `attr_private_initialize`) and `method_object` to really cut down on the boilerplate.
|
12
|
+
|
9
13
|
Instead of
|
10
14
|
|
11
15
|
``` ruby
|
12
|
-
class
|
13
|
-
def initialize(invoice,
|
14
|
-
@invoice
|
16
|
+
class InvoicePolicy
|
17
|
+
def initialize(invoice, company:)
|
18
|
+
@invoice = invoice
|
19
|
+
@company = company
|
20
|
+
end
|
21
|
+
|
22
|
+
def payable?
|
23
|
+
some_logic(invoice, company)
|
15
24
|
end
|
16
25
|
|
17
26
|
private
|
18
27
|
|
19
|
-
attr_reader :invoice, :
|
28
|
+
attr_reader :invoice, :company
|
20
29
|
end
|
21
30
|
```
|
22
31
|
|
@@ -24,11 +33,58 @@ you can just do
|
|
24
33
|
|
25
34
|
``` ruby
|
26
35
|
class InvoiceBuilder
|
27
|
-
pattr_initialize :invoice, :
|
36
|
+
pattr_initialize :invoice, [:company!]
|
37
|
+
|
38
|
+
def payable?
|
39
|
+
some_logic(invoice, company)
|
40
|
+
end
|
28
41
|
end
|
29
42
|
```
|
30
43
|
|
31
|
-
|
44
|
+
And instead of
|
45
|
+
|
46
|
+
``` ruby
|
47
|
+
class PayInvoice
|
48
|
+
def self.call(invoice, amount)
|
49
|
+
new(invoice, amount).call
|
50
|
+
end
|
51
|
+
|
52
|
+
def initialize(invoice, amount)
|
53
|
+
@invoice = invoice
|
54
|
+
@amount = amount
|
55
|
+
end
|
56
|
+
|
57
|
+
def call
|
58
|
+
PaymentGateway.charge(invoice.id, amount_in_cents)
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def amount_in_cents
|
64
|
+
amount * 100
|
65
|
+
end
|
66
|
+
|
67
|
+
attr_reader :invoice, :amount
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
you can just do
|
72
|
+
|
73
|
+
``` ruby
|
74
|
+
class PayInvoice
|
75
|
+
method_object :invoice, :amount
|
76
|
+
|
77
|
+
def call
|
78
|
+
PaymentGateway.charge(invoice.id, amount_in_cents)
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def amount_in_cents
|
84
|
+
amount * 100
|
85
|
+
end
|
86
|
+
end
|
87
|
+
```
|
32
88
|
|
33
89
|
Supports positional arguments as well as optional and required keyword arguments.
|
34
90
|
|
data/attr_extras.gemspec
CHANGED
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.require_paths = ["lib"]
|
15
15
|
gem.license = "MIT"
|
16
16
|
gem.version = AttrExtras::VERSION
|
17
|
+
gem.metadata = { "rubygems_mfa_required" => "true" }
|
17
18
|
|
18
19
|
gem.add_development_dependency "minitest", ">= 5"
|
19
20
|
gem.add_development_dependency "m", "~> 1.5.1" # Running individual tests.
|
data/lib/attr_extras/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attr_extras
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.2.
|
4
|
+
version: 6.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrik Nyh
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2021-11-19 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: minitest
|
@@ -63,8 +63,8 @@ executables: []
|
|
63
63
|
extensions: []
|
64
64
|
extra_rdoc_files: []
|
65
65
|
files:
|
66
|
+
- ".github/workflows/ci.yml"
|
66
67
|
- ".gitignore"
|
67
|
-
- ".travis.yml"
|
68
68
|
- CHANGELOG.md
|
69
69
|
- Gemfile
|
70
70
|
- LICENSE.txt
|
@@ -102,7 +102,8 @@ files:
|
|
102
102
|
homepage: https://github.com/barsoom/attr_extras
|
103
103
|
licenses:
|
104
104
|
- MIT
|
105
|
-
metadata:
|
105
|
+
metadata:
|
106
|
+
rubygems_mfa_required: 'true'
|
106
107
|
post_install_message:
|
107
108
|
rdoc_options: []
|
108
109
|
require_paths:
|
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
119
|
- !ruby/object:Gem::Version
|
119
120
|
version: '0'
|
120
121
|
requirements: []
|
121
|
-
rubygems_version: 3.
|
122
|
+
rubygems_version: 3.2.28
|
122
123
|
signing_key:
|
123
124
|
specification_version: 4
|
124
125
|
summary: Takes some boilerplate out of Ruby with methods like attr_initialize.
|