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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5bcafa6587f9210c87ea5156944ca31f979ff3f88967901cbd8dc1a74e17639b
4
- data.tar.gz: 524208f6a87cd9b00f8984900a25b9d547480ab5b0da48db583a48c244418deb
3
+ metadata.gz: 1bf8daea867adfaeae359d3ed4746d574faa7de26e3b5d95ceaae75c76b756c3
4
+ data.tar.gz: 3d88629682457b5b9fe3d2181f2cefce839ff75ef62afac0365810ff20b2d622
5
5
  SHA512:
6
- metadata.gz: e217d93d28711d73f503fd8300125993a08cfbd0c412259eaa7372af83a59dde50c20ee409ca9763543afd05c61ed8e4337443cf28fe1309bf728de06b4db6c1
7
- data.tar.gz: 5591eab6405a51a363acbd962bfa8947b1cff474f0d8b8aea620cac6b3897cb575aa471f8acd93387078271e88f76433d7d9c898a68255c6b7490b63a3ede599
6
+ metadata.gz: 676dfa2bbfe6e4460e262deaece0350d4fbd52b4ae5bd62546104322cc4002c6c5ce85146f994ea86ebde1b75b7b2fb18400186e163a7ad419f5a9b56070d863
7
+ data.tar.gz: 90a7d51b3b9fb35d342a7b64257d001fc985c6820c4b5a8b28bd27fd46b26cdaef571ca961a094bfb32c16c6774234530dce14e7d03f11c39224e8e178d8aacb
@@ -4,3 +4,11 @@ require:
4
4
 
5
5
  inherit_gem:
6
6
  standard: config/base.yml
7
+
8
+ AllCops:
9
+ DisplayCopNames: true
10
+ Exclude:
11
+ - 'bin/*'
12
+ - 'Gemfile'
13
+ - 'tmp/**/*'
14
+ - 'vendor/**/*'
@@ -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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- callee (0.1.2)
4
+ callee (0.1.3)
5
5
  dry-initializer (>= 2.5, < 4.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Callee
2
2
 
3
+ [![Build Status](https://travis-ci.org/dreikanter/callee.svg?branch=master)](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 SumService
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
- SumService.call(1, 1) # Will return 2
39
+ Sum.call(1, 1) # => 2
38
40
  ```
39
41
 
40
- And one more example, to demonstrate optional params with default values:
42
+ Use optional params with default values:
41
43
 
42
44
  ``` ruby
43
- class GreetingService
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
- GreetingService.call # Will return "Hello!"
55
- GreetingService.call(name: 'Probert') # Will return "Hello, Probert!"
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
- 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/)).
104
+ See [more examples](https://dry-rb.org/gems/dry-initializer/type-constraints/) in dry-rb docs.
59
105
 
60
106
  ## Development
61
107
 
@@ -11,6 +11,10 @@ module Callee
11
11
  def call(*args, **kwargs)
12
12
  new(*args, **kwargs).call
13
13
  end
14
+
15
+ def to_proc
16
+ method(:call).to_proc
17
+ end
14
18
  end
15
19
 
16
20
  def call
@@ -1,3 +1,3 @@
1
1
  module Callee
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
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.1.2
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-28 00:00:00.000000000 Z
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
- rubyforge_project:
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