direct 2.1.0 → 2.1.1

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: 4b89861d3e32e540516068bfc32e68400da28980ab260a14c9d0225b4cf12f78
4
- data.tar.gz: 2a9134c83f29c6409bbf00c1d57272fbc6f1a5a907a1501cb903abd1fc8cd4c9
3
+ metadata.gz: 6cafb03ba4135aee7c3683cff6334c95e55994d9849aa33a6eeddba5ca8d8b71
4
+ data.tar.gz: 2abaf68430f7fb3f5c5fbac561224ce7d642b030d36b386837815b079e148973
5
5
  SHA512:
6
- metadata.gz: 5ff7abfcc77044b071373176421637e193400b1e019a2a9be3689ceff5326d862d9a9f005a28f80a45d83102b96e6252532e504e11ae731ff44df65e60edcba5
7
- data.tar.gz: 45418478b7ac061e2d41a2b066230673300d840ee70f7cee928fa282f5d44c2fca0784302d33df6d752f21a3dd639330e564e3048626d5785280b23e40987352
6
+ metadata.gz: 55bac619c4e84de160146643cc7a08fdd9d003a54c0929ae8bd01fa08cbdd83a9611e8fda40fc9804f5e5fe5120ca4b0598ce56cc687ce20ceaec7feedc6dbfa
7
+ data.tar.gz: 7b51129f30eefaa4ea957ccc1946083f40d7d0dcaa208e5f8d4ebf791249007c9d3eaa51236f7491295fe3baf68aacc4385248aac39d0f82c55ecf9d6d65260d
data/CHANGELOG.md CHANGED
@@ -1,33 +1,12 @@
1
- ## Version 2.1.0
1
+ # Changelog
2
2
 
3
- Check for inheritance on exception handler exceptions.
4
- ## Version 2.0.1
3
+ All notable changes to this project will be documented in this file.
5
4
 
6
- Introduce an ExceptionHandler to allow for multiple exception blocks
7
- Drop Ruby 2.6 support
8
- Fix bug where strict_defer was not accepting callable and object arguments.
9
- Drop Ruby 2.5 and below
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
+ and this project adheres to [Semantic Versioning](http://semver.org/).
10
7
 
11
- ## Version 2.0.0
8
+ ## [2.1.1] - 2025-10-17
12
9
 
13
- A bug in deferred execution did not return the success/failure results. Fixes test names that cause a collision and incorrect test scenarios.
10
+ ### Added
14
11
 
15
- ## Version 1.2.1
16
-
17
- Provide an 'object:' to a Direct.defer or Direct.strict_defer to be sent as the third parameter in the executed blocks.
18
-
19
- ## Version 1.2.0
20
-
21
- Provide a Direct.defer and Direct.strict_defer to allow deferring blocks without success and failure procedures.
22
-
23
- ## Version 1.1.1
24
-
25
- Include Direct.allow_missing_directions to allow as_directed to be ignored when missing.
26
-
27
- ## Version 1.1.0
28
-
29
- Use Direct module to build deferred object internals.
30
-
31
- ## Version 1.0.0
32
-
33
- Initial release
12
+ - Reissue for version and release management. (2c90cd0)
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018-2022 Jim Gay
3
+ Copyright (c) 2018-2025 Jim Gay
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
+ require "reissue/gem"
3
4
 
4
5
  Rake::TestTask.new(:test) do |t|
5
6
  t.libs << "test"
@@ -7,4 +8,10 @@ Rake::TestTask.new(:test) do |t|
7
8
  t.test_files = FileList["test/**/*_test.rb"]
8
9
  end
9
10
 
11
+ Reissue::Task.create :reissue do |task|
12
+ task.version_file = "lib/direct/version.rb"
13
+ task.changelog_file = "CHANGELOG.md"
14
+ task.fragment = :git
15
+ end
16
+
10
17
  task default: :test
@@ -3,18 +3,23 @@ module Direct
3
3
  class ExceptionHandler
4
4
  def initialize
5
5
  @handlers = {}
6
+ @classes_cache = nil
6
7
  end
7
8
 
8
9
  # All classes, including StandardError, for which this object
9
10
  # maintains a block to execute.
10
11
  def classes
11
- [StandardError, @handlers.keys.flatten].flatten
12
+ @classes_cache ||= begin
13
+ return [StandardError] if @handlers.empty?
14
+ [StandardError, *@handlers.keys.flatten].uniq
15
+ end
12
16
  end
13
17
 
14
18
  # Pass a single or multiple exception classes and the block
15
19
  # to be used to handle them.
16
20
  def monitor(*classes, &block)
17
21
  @handlers[classes.flatten] = block
22
+ @classes_cache = nil
18
23
  end
19
24
 
20
25
  # This will find the first handler given to `monitor` which matches
@@ -22,15 +27,22 @@ module Direct
22
27
  # deferred object, the exception object, and any given object to the
23
28
  # deferred object.
24
29
  def call(deferred, exception, object)
25
- if_none = proc { raise "No handler for this exception: #{exception.class}!" }
26
- result = @handlers.find { |key, val| key.include?(exception.class) }
27
- if result.nil?
28
- result = @handlers.find(if_none) do |key, val|
29
- key.find { |klass| exception.class < klass }
30
- end
30
+ exception_class = exception.class
31
+
32
+ # Fast path: exact class match
33
+ result = @handlers.find { |keys, _| keys.include?(exception_class) }
34
+ return result.last.call(deferred, exception, object) if result
35
+
36
+ # Slow path: inheritance check
37
+ result = @handlers.find do |keys, _|
38
+ keys.any? { |klass| exception_class < klass }
31
39
  end
32
40
 
33
- result.last.call(deferred, exception, object)
41
+ if result
42
+ result.last.call(deferred, exception, object)
43
+ else
44
+ raise "No handler for this exception: #{exception_class}!"
45
+ end
34
46
  end
35
47
  end
36
48
  end
@@ -42,21 +42,25 @@ module Direct
42
42
  # puts "The #{thing} did something!"
43
43
  # }.execute
44
44
  #
45
- def initialize(callable = nil, *args, **kwargs, &block)
46
- @object = kwargs.delete(:object)
45
+ def initialize(callable = nil, *args, object: nil, exception_handler: nil, **kwargs, &block)
46
+ @object = object
47
47
  @args = args
48
48
  @kwargs = kwargs
49
- @exception_handler = kwargs.delete(:exception_handler) || ExceptionHandler.new
49
+ @exception_handler = exception_handler
50
50
  @execution = callable || block
51
51
  end
52
- attr_reader :execution, :exception_handler, :object, :args, :kwargs
52
+ attr_reader :execution, :object, :args, :kwargs
53
+
54
+ def exception_handler
55
+ @exception_handler ||= ExceptionHandler.new
56
+ end
53
57
 
54
58
  # Tell the object what to do for a success path
55
59
  #
56
60
  # Returns itself
57
61
  #
58
62
  def success(callable = nil, &block)
59
- direct(:success, (callable || block))
63
+ direct(:success, callable || block)
60
64
  self
61
65
  end
62
66
 
@@ -65,7 +69,7 @@ module Direct
65
69
  # Returns itself
66
70
  #
67
71
  def failure(callable = nil, &block)
68
- direct(:failure, (callable || block))
72
+ direct(:failure, callable || block)
69
73
  self
70
74
  end
71
75
 
@@ -125,7 +129,6 @@ module Direct
125
129
  end || result
126
130
  end
127
131
  private :trigger_directions
128
-
129
132
  end
130
133
 
131
134
  private_constant :Executable
@@ -1,3 +1,3 @@
1
1
  module Direct
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.1"
3
3
  end
data/lib/direct.rb CHANGED
@@ -6,6 +6,7 @@ module Direct
6
6
 
7
7
  module AllowMissing
8
8
  include Direct
9
+
9
10
  def allow_missing_directions?
10
11
  true
11
12
  end
@@ -107,10 +108,12 @@ module Direct
107
108
  # The current value for self will be sent as the first argument to the block
108
109
  def as_directed(key, ...)
109
110
  return if allow_missing_directions? && __directions.empty?
110
- __directions.fetch(key).map do |block|
111
- block.call(self, ...)
111
+
112
+ # Fast path: check if key exists before rescue handling
113
+ if __directions.key?(key)
114
+ return __directions.fetch(key).map { |block| block.call(self, ...) }
112
115
  end
113
- rescue KeyError
116
+
114
117
  return if allow_missing_directions?
115
118
  raise MissingProcedure, "Procedure for :#{key} was reached but not specified."
116
119
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: direct
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Gay
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-05-27 00:00:00.000000000 Z
10
+ date: 2025-10-18 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: concurrent-ruby
@@ -46,7 +45,6 @@ homepage: https://github.com/saturnflyer/direct
46
45
  licenses:
47
46
  - MIT
48
47
  metadata: {}
49
- post_install_message:
50
48
  rdoc_options: []
51
49
  require_paths:
52
50
  - lib
@@ -61,8 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
59
  - !ruby/object:Gem::Version
62
60
  version: '0'
63
61
  requirements: []
64
- rubygems_version: 3.4.10
65
- signing_key:
62
+ rubygems_version: 3.6.5
66
63
  specification_version: 4
67
64
  summary: Direct objects to perform arbitrary blocks by name
68
65
  test_files: []