direct 1.1.0 → 1.1.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
  SHA256:
3
- metadata.gz: fa39232af5f66ca2043ac1b5e258a26e6869b8c012ccaa0661080e89a7644ea8
4
- data.tar.gz: 2d9ad86998c6903f6c3146258cf278ec0deac829ac96e8ffb85f47967e1e2c4c
3
+ metadata.gz: 98778b7710dd0641ba88486adc2888551cd823ec4be17494857d42555af8e72a
4
+ data.tar.gz: b0216ba7745d33ff0f6cf3f1018472d19a8ec3df00b2678bcda68f4074a125d4
5
5
  SHA512:
6
- metadata.gz: 4afc48c61d7b189f49b016af2419f54f03a114d5ad5cfcfcfeaa12373e8787d655b651f223e1b9f45b3adef88124c701f452c6077fc3bdc76380d5a3597ed415
7
- data.tar.gz: bef096a5f6212ca376b919ed1238da53571a9fea95631352686acfe49c6ea8b1b7ec071496dfebbdfd33537c81e7cafefad894eaf6d9e668fbc4cfb03ad3883b
6
+ metadata.gz: 1fd862dec144d24f9268574cc91a1fae0a9b90052598d2c3f221b5cc23cd383d60966d600db20ba8551751bd11344a2ca8f79b9563cd834dce941569dc08e0cf
7
+ data.tar.gz: 734e1c4f6095c2c5d7566ba607a438000298e28b1c2d352ba9c93a17ea3e7249956119b69b9e1d6184716006fc158ad5394b03e139c44f5f7f7f0972d549af97
@@ -1,3 +1,7 @@
1
+ ## Version 1.1.1
2
+
3
+ Include Direct.allow_missing_directions to allow as_directed to be ignored when missing.
4
+
1
5
  ## Version 1.1.0
2
6
 
3
7
  Use Direct module to build deferred object internals.
@@ -7,6 +7,32 @@ require "direct/group"
7
7
  module Direct
8
8
  class MissingProcedure < StandardError; end
9
9
 
10
+ module AllowMissing
11
+ include Direct
12
+ def allow_missing_directions?
13
+ true
14
+ end
15
+ end
16
+
17
+ # Use this module to allow your procedures to go ignored.
18
+ #
19
+ # Example:
20
+ #
21
+ # class Thing < ActiveRecord::Base
22
+ # include Direct.allow_missing_directions
23
+ #
24
+ # def save(*)
25
+ # super
26
+ # as_directed(:success)
27
+ # end
28
+ # end
29
+ #
30
+ # Thing.new.save # => no MissingProcedure error raised.
31
+ #
32
+ def self.allow_missing_directions
33
+ AllowMissing
34
+ end
35
+
10
36
  # Wrap a block of code to return an object for handling
11
37
  # success or failure.
12
38
  #
@@ -57,15 +83,21 @@ module Direct
57
83
  #
58
84
  # This will raise an error if the provided key is not found
59
85
  def as_directed(key, *args)
86
+ return if allow_missing_directions? && __directions.empty?
60
87
  __directions.fetch(key).map do |block|
61
88
  block.call(self, *args)
62
89
  end
63
90
  rescue KeyError
91
+ return if allow_missing_directions?
64
92
  raise MissingProcedure, "Procedure for :#{key} was reached but not specified."
65
93
  end
66
94
 
67
95
  private
68
96
 
97
+ def allow_missing_directions?
98
+ false
99
+ end
100
+
69
101
  def __directions
70
102
  @__directions ||= Direct::Group.new
71
103
  end
@@ -22,5 +22,13 @@ module Direct
22
22
  def key?(key)
23
23
  map.key?(key)
24
24
  end
25
+
26
+ def empty?
27
+ map.empty?
28
+ end
29
+
30
+ def inspect
31
+ map.keys.inspect
32
+ end
25
33
  end
26
34
  end
@@ -1,3 +1,3 @@
1
1
  module Direct
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: direct
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Gay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-11 00:00:00.000000000 Z
11
+ date: 2019-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -93,7 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  requirements: []
96
- rubygems_version: 3.0.2
96
+ rubyforge_project:
97
+ rubygems_version: 2.7.6
97
98
  signing_key:
98
99
  specification_version: 4
99
100
  summary: Direct objects to perform arbitrary blocks by name