callee 0.1.1 → 0.1.2
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/CHANGELOG.md +6 -1
- data/Gemfile.lock +1 -1
- data/README.md +37 -4
- data/lib/callee/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bcafa6587f9210c87ea5156944ca31f979ff3f88967901cbd8dc1a74e17639b
|
4
|
+
data.tar.gz: 524208f6a87cd9b00f8984900a25b9d547480ab5b0da48db583a48c244418deb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e217d93d28711d73f503fd8300125993a08cfbd0c412259eaa7372af83a59dde50c20ee409ca9763543afd05c61ed8e4337443cf28fe1309bf728de06b4db6c1
|
7
|
+
data.tar.gz: 5591eab6405a51a363acbd962bfa8947b1cff474f0d8b8aea620cac6b3897cb575aa471f8acd93387078271e88f76433d7d9c898a68255c6b7490b63a3ede599
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,11 @@ 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.
|
7
|
+
## [0.1.2] - 2019-07-28
|
8
|
+
|
9
|
+
- Added a readme.
|
10
|
+
- Relaxed dependencies.
|
11
|
+
|
12
|
+
## [0.1.1] - 2019-07-27
|
8
13
|
|
9
14
|
- First public release.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Callee
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
This gem helps to define callable classes with strict params specification.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,42 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
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
|
+
|
25
|
+
``` ruby
|
26
|
+
class SumService
|
27
|
+
include Callee
|
28
|
+
|
29
|
+
param :a
|
30
|
+
param :b
|
31
|
+
|
32
|
+
def call
|
33
|
+
a + b
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
SumService.call(1, 1) # Will return 2
|
38
|
+
```
|
39
|
+
|
40
|
+
And one more example, to demonstrate optional params with default values:
|
41
|
+
|
42
|
+
``` ruby
|
43
|
+
class GreetingService
|
44
|
+
include Callee
|
45
|
+
|
46
|
+
option :greeting, optional: true, default: proc { 'Hello' }
|
47
|
+
option :name, optional: true
|
48
|
+
|
49
|
+
def call
|
50
|
+
"#{[greeting, name].compact.join(', ')}!"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
GreetingService.call # Will return "Hello!"
|
55
|
+
GreetingService.call(name: 'Probert') # Will return "Hello, Probert!"
|
56
|
+
```
|
57
|
+
|
58
|
+
Type constraints and coercion will also work, as usual, just make sure to include `dry-types` (here are [some examples)](https://dry-rb.org/gems/dry-initializer/type-constraints/)).
|
26
59
|
|
27
60
|
## Development
|
28
61
|
|
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.2
|
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-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-initializer
|