callee 0.1.2 → 0.1.3
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/.rubocop.yml +8 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +53 -7
- data/lib/callee.rb +4 -0
- data/lib/callee/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bf8daea867adfaeae359d3ed4746d574faa7de26e3b5d95ceaae75c76b756c3
|
4
|
+
data.tar.gz: 3d88629682457b5b9fe3d2181f2cefce839ff75ef62afac0365810ff20b2d622
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 676dfa2bbfe6e4460e262deaece0350d4fbd52b4ae5bd62546104322cc4002c6c5ce85146f994ea86ebde1b75b7b2fb18400186e163a7ad419f5a9b56070d863
|
7
|
+
data.tar.gz: 90a7d51b3b9fb35d342a7b64257d001fc985c6820c4b5a8b28bd27fd46b26cdaef571ca961a094bfb32c16c6774234530dce14e7d03f11c39224e8e178d8aacb
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [0.1.3] - 2019-07-29
|
8
|
+
|
9
|
+
- Implement `to_proc` method to support Ruby ampersand shorthand.
|
10
|
+
|
7
11
|
## [0.1.2] - 2019-07-28
|
8
12
|
|
9
13
|
- Added a readme.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Callee
|
2
2
|
|
3
|
+
[](https://travis-ci.org/dreikanter/callee)
|
4
|
+
|
3
5
|
This gem helps to define callable classes with strict params specification.
|
4
6
|
|
5
7
|
## Installation
|
@@ -23,7 +25,7 @@ Or install it yourself as:
|
|
23
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:
|
24
26
|
|
25
27
|
``` ruby
|
26
|
-
class
|
28
|
+
class Sum
|
27
29
|
include Callee
|
28
30
|
|
29
31
|
param :a
|
@@ -34,13 +36,13 @@ class SumService
|
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
37
|
-
|
39
|
+
Sum.call(1, 1) # => 2
|
38
40
|
```
|
39
41
|
|
40
|
-
|
42
|
+
Use optional params with default values:
|
41
43
|
|
42
44
|
``` ruby
|
43
|
-
class
|
45
|
+
class Greet
|
44
46
|
include Callee
|
45
47
|
|
46
48
|
option :greeting, optional: true, default: proc { 'Hello' }
|
@@ -51,11 +53,55 @@ class GreetingService
|
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
+
Greet.call # => "Hello!"
|
57
|
+
Greet.call(name: 'Probert') # => "Hello, Probert!"
|
58
|
+
```
|
59
|
+
|
60
|
+
Callable class may be used as a `Proc`:
|
61
|
+
|
62
|
+
``` 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]
|
77
|
+
```
|
78
|
+
|
79
|
+
Since Callee mixin inherits `dry-initializer` DSL, type constraints and coercion will also work, as usual. Just make sure to include `dry-types`:
|
80
|
+
|
81
|
+
``` ruby
|
82
|
+
require "dry-types"
|
83
|
+
|
84
|
+
class StrictPower
|
85
|
+
include Callee
|
86
|
+
|
87
|
+
param :value, type: Dry::Types["strict.integer"]
|
88
|
+
|
89
|
+
def call
|
90
|
+
value * value
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class CoerciblePower < StrictPower
|
95
|
+
param :value, type: Dry::Types["coercible.integer"]
|
96
|
+
end
|
97
|
+
|
98
|
+
string_values = %w[1 2 3]
|
99
|
+
|
100
|
+
pp string_values.map(&StrictPower) # Will raise Dry::Types::ConstraintError
|
101
|
+
pp string_values.map(&CoerciblePower) # => [1, 4, 9]
|
56
102
|
```
|
57
103
|
|
58
|
-
|
104
|
+
See [more examples](https://dry-rb.org/gems/dry-initializer/type-constraints/) in dry-rb docs.
|
59
105
|
|
60
106
|
## Development
|
61
107
|
|
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.1.
|
4
|
+
version: 0.1.3
|
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-07-
|
11
|
+
date: 2019-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-initializer
|
@@ -240,8 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
240
240
|
- !ruby/object:Gem::Version
|
241
241
|
version: '0'
|
242
242
|
requirements: []
|
243
|
-
|
244
|
-
rubygems_version: 2.7.6
|
243
|
+
rubygems_version: 3.0.3
|
245
244
|
signing_key:
|
246
245
|
specification_version: 4
|
247
246
|
summary: Make callable service classes
|