dry-behaviour 0.3.0 → 0.3.1

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
  SHA1:
3
- metadata.gz: b13f2aa8db1f551224ff33dcd3852140b4ae525d
4
- data.tar.gz: 673da500d0a752c18c9fcbd6d3b0c05632ce7491
3
+ metadata.gz: 4a166f19773e33836c9c2a8bf2440166c735a55b
4
+ data.tar.gz: 80deda3626f5a67ccbbb317e0595f4a86981cf40
5
5
  SHA512:
6
- metadata.gz: a13e840444e1fd5afd9c57dab48c15200be1980549ca2763799c684f1b00546361068d47a8c77c2cd8c8ffd46dbb0fca408b4028c8c03847f340ddbaf55b5075
7
- data.tar.gz: 2009af8683aad93908598415d69e1ac3cdabdc6de97dc76a6312bf41afc8ca7118ba0f632f4e9cc15d1cecf00a848a769babcf52f90e37a68303d15d6129c6cf
6
+ metadata.gz: 5bceef51d78eff3bc1f738cab5ce30baa3215d4507a3c7ec5ff080166b98974cc11b3be47db8694ae4aad290d3d7b3a9633a0d0396cdeb7e7987792ac43eb0d6
7
+ data.tar.gz: ea08dff7a62904ebcfde0799c50218ebc0f43b51fc98cf09f15b1a0163eccdcae4fa965e5c7622563a0e2aa73b5db015dc92ac67591f785ba6230811717821f9
data/.travis.yml CHANGED
@@ -4,4 +4,5 @@ rvm:
4
4
  - 2.1.10
5
5
  - 2.2.2
6
6
  - 2.3.1
7
+ - 2.4.0
7
8
  before_install: gem install bundler -v 1.10.6
data/README.md CHANGED
@@ -64,6 +64,10 @@ expect(Protocols::Adder.add_default(1)).to eq(6)
64
64
 
65
65
  ## Changelog
66
66
 
67
+ ### `0.3.1` :: `implemented_for?` and `implementation_for`
68
+
69
+ ### `0.3.0` :: version bump
70
+
67
71
  ### `0.2.2` :: meaningful errors
68
72
 
69
73
  #### Throws an exception on wrong usage:
@@ -28,11 +28,15 @@ module Dry
28
28
  raise Dry::Protocol::NotImplemented.new(:method, self.inspect, method)
29
29
  end
30
30
 
31
+ singleton_class.send :define_method, :implementation_for do |receiver|
32
+ receiver.class.ancestors.lazy.map do |c|
33
+ BlackTie.implementations[self].fetch(c, nil)
34
+ end.reject(&:nil?).first
35
+ end
36
+
31
37
  BlackTie.protocols[self].each do |method, *_| # FIXME: CHECK PARAMS CORRESPONDENCE HERE
32
38
  singleton_class.send :define_method, method do |receiver = nil, *args|
33
- impl = receiver.class.ancestors.lazy.map do |c|
34
- BlackTie.implementations[self].fetch(c, nil)
35
- end.reject(&:nil?).first
39
+ impl = implementation_for(receiver)
36
40
 
37
41
  raise Dry::Protocol::NotImplemented.new(:protocol, self.inspect, receiver.class) unless impl
38
42
  impl[method].(*args.unshift(receiver))
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Behaviour
3
- VERSION = '0.3.0'.freeze
3
+ VERSION = '0.3.1'.freeze
4
4
  end
5
5
  end
data/lib/dry/behaviour.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'dry/behaviour/version'
2
2
  require 'dry/errors/not_implemented'
3
+ require 'dry/errors/not_protocol'
3
4
  require 'dry/behaviour/black_tie'
4
5
 
5
6
  module Dry
@@ -14,6 +15,11 @@ module Dry
14
15
  Dry::BlackTie.defimpl(protocol, target: target, delegate: delegate, map: map, &λ)
15
16
  end
16
17
  # rubocop:enable Style/AsciiIdentifiers
18
+
19
+ def implemented_for?(protocol, receiver)
20
+ raise NotProtocol.new(protocol) unless protocol < ::Dry::Protocol
21
+ !protocol.implementation_for(receiver).nil?
22
+ end
17
23
  end
18
24
  end
19
25
  end
@@ -0,0 +1,9 @@
1
+ module Dry
2
+ module Protocol
3
+ class NotProtocol < StandardError
4
+ def initialize(suspect)
5
+ super "“#{suspect.inspect}” is not a protocol."
6
+ end
7
+ end
8
+ end
9
+ 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.3.0
4
+ version: 0.3.1
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-11-11 00:00:00.000000000 Z
13
+ date: 2017-01-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -94,6 +94,7 @@ files:
94
94
  - lib/dry/behaviour/black_tie.rb
95
95
  - lib/dry/behaviour/version.rb
96
96
  - lib/dry/errors/not_implemented.rb
97
+ - lib/dry/errors/not_protocol.rb
97
98
  homepage: https://kantox.com/
98
99
  licenses:
99
100
  - MIT