dry-behaviour 0.2.1 → 0.2.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/README.md +11 -0
- data/lib/dry/behaviour/black_tie.rb +10 -4
- data/lib/dry/behaviour/version.rb +1 -1
- data/lib/dry/behaviour.rb +1 -0
- data/lib/dry/errors/not_implemented.rb +16 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45f2aaaadec62efcc2ab74af6422cae3b49cff4d
|
4
|
+
data.tar.gz: cf9a16b0019b6b332cdac2114e1714d670f94af5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1a687fcb6a2aaeb7e545776e5abd71a195642f7fdfe17fb110fa94dd30e0db0a3530f1898817dc79a11cb786d8a4330e839c3af4871633a0e3c141fe45cff92
|
7
|
+
data.tar.gz: 4c5e2a3e2930acdb3fd02200ddd641e9f8f15bab423e9dfeea799951fb2163fb36c38cab24acc0212d434eefd26a61820b962894b4bce7a1830a32cd2bce00d3
|
data/README.md
CHANGED
@@ -64,6 +64,17 @@ expect(Protocols::Adder.add_default(1)).to eq(6)
|
|
64
64
|
|
65
65
|
## Changelog
|
66
66
|
|
67
|
+
### `0.2.2` :: meaningful errors
|
68
|
+
|
69
|
+
#### Throws an exception on wrong usage:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
Protocols::Adder.add({}, 42)
|
73
|
+
#⇒ Protocols::NotImplemented: Protocol “Protocols::Adder” is not implemented for “Hash”
|
74
|
+
Protocols::Adder.hello({}, 42)
|
75
|
+
#⇒ Protocols::NotImplemented: Protocol “Protocols::Adder” does not declare method “hello”
|
76
|
+
```
|
77
|
+
|
67
78
|
### `0.2.1` :: multiple targets
|
68
79
|
|
69
80
|
#### Multiple targets:
|
@@ -24,12 +24,18 @@ module Dry
|
|
24
24
|
class_eval(&Proc.new)
|
25
25
|
(instance_methods(false) - ims).each { |m| class_eval { module_function m } }
|
26
26
|
|
27
|
+
singleton_class.send :define_method, :method_missing do |method, *args|
|
28
|
+
raise Dry::Protocol::NotImplemented.new(:method, self.inspect, method)
|
29
|
+
end
|
30
|
+
|
27
31
|
BlackTie.protocols[self].each do |method, *_| # FIXME: CHECK PARAMS CORRESPONDENCE HERE
|
28
|
-
|
29
|
-
|
30
|
-
receiver.class.ancestors.lazy.map do |c|
|
32
|
+
singleton_class.send :define_method, method do |receiver = nil, *args|
|
33
|
+
impl = receiver.class.ancestors.lazy.map do |c|
|
31
34
|
BlackTie.implementations[self].fetch(c, nil)
|
32
|
-
end.reject(&:nil?).first
|
35
|
+
end.reject(&:nil?).first
|
36
|
+
|
37
|
+
raise Dry::Protocol::NotImplemented.new(:protocol, self.inspect, receiver.class) unless impl
|
38
|
+
impl[method].(*args.unshift(receiver))
|
33
39
|
end
|
34
40
|
end
|
35
41
|
end
|
data/lib/dry/behaviour.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Dry
|
2
|
+
module Protocol
|
3
|
+
class NotImplemented < StandardError
|
4
|
+
def initialize(type, proto, impl)
|
5
|
+
super case type
|
6
|
+
when :protocol
|
7
|
+
"Protocol “#{proto}” is not implemented for “#{impl}”."
|
8
|
+
when :method
|
9
|
+
"Protocol “#{proto}” does not declare method “#{impl}”."
|
10
|
+
else
|
11
|
+
"Protocol “#{proto}” is invalid."
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-behaviour
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksei Matiushkin
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-11-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/dry/behaviour.rb
|
94
94
|
- lib/dry/behaviour/black_tie.rb
|
95
95
|
- lib/dry/behaviour/version.rb
|
96
|
+
- lib/dry/errors/not_implemented.rb
|
96
97
|
homepage: https://kantox.com/
|
97
98
|
licenses:
|
98
99
|
- MIT
|
@@ -113,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
114
|
version: '0'
|
114
115
|
requirements: []
|
115
116
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.4.
|
117
|
+
rubygems_version: 2.4.6
|
117
118
|
signing_key:
|
118
119
|
specification_version: 4
|
119
120
|
summary: Tiny library inspired by Elixir protocol pattern.
|