callee 0.2.2 → 0.3.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/gpr.yml +33 -0
- data/.github/workflows/rubygems.yml +32 -0
- data/.github/workflows/test.yml +40 -0
- data/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +16 -40
- data/lib/callee.rb +2 -2
- data/lib/callee/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cd3eb00898ba86ebe6cac2bdcfcfe9a38b3a9c6d1a11560e9059b0228e6a9d7
|
4
|
+
data.tar.gz: 2d9da3e5362ef6396c0363c8705680afe1d790cb529398020e558112526cc320
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0a17b8c9882e591bc6f4d65cff41ddc9e167df1fcde57526cd768cdc58cbc9ae0158eba17dcf5add6a5b3aa3150454ddc84223ca3fe83ab2ad65f7ce58506d1
|
7
|
+
data.tar.gz: 8357f85f64715b32b591473d8dfeedcfcdb86eeabedd627168a3d179be5b63afa7e18598a0b92d8eb480cdb3946dbc95b3de09a17f736e5fd51aee84f6e85ffc
|
@@ -0,0 +1,33 @@
|
|
1
|
+
name: Release on GitHub
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches:
|
6
|
+
- releases
|
7
|
+
push:
|
8
|
+
branches:
|
9
|
+
- releases
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
build:
|
13
|
+
name: Build + Publish
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@master
|
18
|
+
- name: Set up Ruby
|
19
|
+
uses: actions/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
version: 2.6.x
|
22
|
+
|
23
|
+
- name: Publish to GPR
|
24
|
+
run: |
|
25
|
+
mkdir -p $HOME/.gem
|
26
|
+
touch $HOME/.gem/credentials
|
27
|
+
chmod 0600 $HOME/.gem/credentials
|
28
|
+
printf -- "---\n:github: Bearer ${GITHUB_TOKEN}\n" > $HOME/.gem/credentials
|
29
|
+
gem build *.gemspec
|
30
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
31
|
+
env:
|
32
|
+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
33
|
+
OWNER: dreikanter
|
@@ -0,0 +1,32 @@
|
|
1
|
+
name: Release on RubyGems
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches:
|
6
|
+
- releases
|
7
|
+
push:
|
8
|
+
branches:
|
9
|
+
- releases
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
build:
|
13
|
+
name: Build + Publish
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@master
|
18
|
+
- name: Set up Ruby
|
19
|
+
uses: actions/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
version: 2.6.x
|
22
|
+
|
23
|
+
- name: Publish to RubyGems
|
24
|
+
run: |
|
25
|
+
mkdir -p $HOME/.gem
|
26
|
+
touch $HOME/.gem/credentials
|
27
|
+
chmod 0600 $HOME/.gem/credentials
|
28
|
+
printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}\n" > $HOME/.gem/credentials
|
29
|
+
gem build *.gemspec
|
30
|
+
gem push *.gem
|
31
|
+
env:
|
32
|
+
RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
name: Test Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
- dev
|
8
|
+
push:
|
9
|
+
branches:
|
10
|
+
- master
|
11
|
+
- dev
|
12
|
+
|
13
|
+
jobs:
|
14
|
+
rubocop:
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v1
|
18
|
+
- name: Set up Ruby
|
19
|
+
uses: actions/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: 2.6.x
|
22
|
+
- name: Run Rubocop
|
23
|
+
run: |
|
24
|
+
gem install bundler
|
25
|
+
bundle install --jobs 4 --retry 3
|
26
|
+
bundle exec rubocop
|
27
|
+
|
28
|
+
test:
|
29
|
+
runs-on: ubuntu-latest
|
30
|
+
steps:
|
31
|
+
- uses: actions/checkout@v1
|
32
|
+
- name: Set up Ruby
|
33
|
+
uses: actions/setup-ruby@v1
|
34
|
+
with:
|
35
|
+
ruby-version: 2.6.x
|
36
|
+
- name: Run tests
|
37
|
+
run: |
|
38
|
+
gem install bundler
|
39
|
+
bundle install --jobs 4 --retry 3
|
40
|
+
bundle exec rake test
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.3
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -25,55 +25,28 @@ Or install it yourself as:
|
|
25
25
|
To make a class callable, you need to include `Callee` mixin and implement `call` instance method. Use [dry-initializer DSL](https://dry-rb.org/gems/dry-initializer/optionals-and-defaults/) to specify calling parameters and options if necessary. Here is a basic usage example:
|
26
26
|
|
27
27
|
``` ruby
|
28
|
-
class
|
29
|
-
include Callee
|
30
|
-
|
31
|
-
param :a
|
32
|
-
param :b
|
33
|
-
|
34
|
-
def call
|
35
|
-
a + b
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
Sum.call(1, 1) # => 2
|
40
|
-
```
|
41
|
-
|
42
|
-
Use optional params with default values:
|
43
|
-
|
44
|
-
``` ruby
|
45
|
-
class Greet
|
28
|
+
class Power
|
46
29
|
include Callee
|
47
30
|
|
48
|
-
|
49
|
-
|
31
|
+
# Required parameter
|
32
|
+
param :base
|
33
|
+
|
34
|
+
# Option with a default value
|
35
|
+
option :exponent, optional: true, default: -> { 2 }
|
50
36
|
|
51
37
|
def call
|
52
|
-
|
38
|
+
base.pow(exponent)
|
53
39
|
end
|
54
40
|
end
|
55
41
|
|
56
|
-
|
57
|
-
|
42
|
+
Power.call(2) # => 4
|
43
|
+
Power.call(2, exponent: 10) # => 1024
|
58
44
|
```
|
59
45
|
|
60
|
-
Callable class may be used as a `
|
46
|
+
Callable class may be used as a Proc. Compact notation in the next example is identical to `[1, 2, 3].map { |value| Power.call(value) }`
|
61
47
|
|
62
48
|
``` ruby
|
63
|
-
|
64
|
-
include Callee
|
65
|
-
|
66
|
-
param :value
|
67
|
-
|
68
|
-
def call
|
69
|
-
value * value
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
values = [1, 2, 3]
|
74
|
-
|
75
|
-
# Compact notation for values.map { |value| Power.call(value) }
|
76
|
-
values.map(&Power) # => [1, 4, 9]
|
49
|
+
[1, 2, 3].map(&Power) # => [1, 4, 9]
|
77
50
|
```
|
78
51
|
|
79
52
|
Since Callee mixin inherits `dry-initializer` DSL, type constraints and coercion will also work, as usual. Just make sure to include `dry-types`:
|
@@ -84,13 +57,16 @@ require "dry-types"
|
|
84
57
|
class StrictPower
|
85
58
|
include Callee
|
86
59
|
|
87
|
-
param :
|
60
|
+
param :base, type: Dry::Types["strict.integer"]
|
61
|
+
option :exponent, type: Dry::Types["strict.integer"], optional: true, default: -> { 2 }
|
88
62
|
|
89
63
|
def call
|
90
|
-
|
64
|
+
base.pow(exponent)
|
91
65
|
end
|
92
66
|
end
|
93
67
|
|
68
|
+
# Let's inherit StrictPower params definition
|
69
|
+
# and override "base" with more forgiving constraint
|
94
70
|
class CoerciblePower < StrictPower
|
95
71
|
param :value, type: Dry::Types["coercible.integer"]
|
96
72
|
end
|
data/lib/callee.rb
CHANGED
data/lib/callee/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: callee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Musayev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-initializer
|
@@ -204,8 +204,12 @@ executables: []
|
|
204
204
|
extensions: []
|
205
205
|
extra_rdoc_files: []
|
206
206
|
files:
|
207
|
+
- ".github/workflows/gpr.yml"
|
208
|
+
- ".github/workflows/rubygems.yml"
|
209
|
+
- ".github/workflows/test.yml"
|
207
210
|
- ".gitignore"
|
208
211
|
- ".rubocop.yml"
|
212
|
+
- ".ruby-version"
|
209
213
|
- ".travis.yml"
|
210
214
|
- CHANGELOG.md
|
211
215
|
- Gemfile
|