callee 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c378b7526324dd89ca9005eee46b5359d3391be9605fa8080f0598848701beb7
4
- data.tar.gz: 756ad3fdddb500b8442405ccb9da602fe382e439f2f176e0703db1c0f83412ac
3
+ metadata.gz: 2cd3eb00898ba86ebe6cac2bdcfcfe9a38b3a9c6d1a11560e9059b0228e6a9d7
4
+ data.tar.gz: 2d9da3e5362ef6396c0363c8705680afe1d790cb529398020e558112526cc320
5
5
  SHA512:
6
- metadata.gz: d4cc1e76eff81c7770366be5264d892f25128ff39d247adaba5f4594a48ff60679a0fe26dc2c2b8e8eab8b154448c62de61d7adba4379341aa4d9fa19883ed32
7
- data.tar.gz: e22dcdd2b21a1f559d055f58ff1a18ea8c34a518333c7e9a4b4f18fbb9ed2fbe900eefb34a1d65ad51d416c92016feaeaa984b2336bbbd9cad5f5b207658655a
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
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.gem
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- callee (0.2.2)
4
+ callee (0.3.0)
5
5
  dry-initializer (>= 2.5, < 4.0)
6
6
 
7
7
  GEM
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 Sum
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
- option :greeting, optional: true, default: proc { 'Hello' }
49
- option :name, optional: true
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
- "#{[greeting, name].compact.join(', ')}!"
38
+ base.pow(exponent)
53
39
  end
54
40
  end
55
41
 
56
- Greet.call # => "Hello!"
57
- Greet.call(name: 'Probert') # => "Hello, Probert!"
42
+ Power.call(2) # => 4
43
+ Power.call(2, exponent: 10) # => 1024
58
44
  ```
59
45
 
60
- Callable class may be used as a `Proc`:
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
- class Power
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 :value, type: Dry::Types["strict.integer"]
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
- value * value
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
@@ -8,8 +8,8 @@ module Callee
8
8
  end
9
9
 
10
10
  module ClassMethods
11
- def call(*params, **options)
12
- create_callable(params, options).call
11
+ def call(*params, **options, &block)
12
+ create_callable(params, options).call(&block)
13
13
  end
14
14
 
15
15
  def to_proc
@@ -1,3 +1,3 @@
1
1
  module Callee
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.2
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-08-07 00:00:00.000000000 Z
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