Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename HookConfiguration to CaptainHook::Configuration #9

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/captain_hook.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require_relative "./hook_configuration"
require_relative "./captain_hook/configuration"

# Strong inspiration on https://github.com/collectiveidea/interactor/blob/master/lib/interactor/hooks.rb
#
Expand Down Expand Up @@ -30,7 +30,7 @@ def hook(
skip_when: nil,
param_builder: nil
)
hooks[kind][hook] = HookConfiguration.new(
hooks[kind][hook] = Configuration.new(
hook: hook,
include: include,
inject: inject,
Expand Down
35 changes: 35 additions & 0 deletions lib/captain_hook/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

module CaptainHook
# Hook configuration parameters these determine how a specific hook will run
class Configuration
def initialize(
hook:,
include: [],
inject: [],
exclude: [],
skip_when: nil,
param_builder: nil
)
@hook = hook
@include = include
@inject = inject
@exclude = exclude
@skip_when = skip_when
@param_builder = param_builder
end

attr_reader :hook, :include, :inject, :exclude, :skip_when, :param_builder

# This determines if this specific hook should be skipped
# depending on the method or arguments.
def skip?(method, *args, **kwargs)
return true if skip_when&.call(args, kwargs)
return true if exclude.include?(method)

return false if include.empty?

!include.include?(method)
end
end
end
33 changes: 0 additions & 33 deletions lib/hook_configuration.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class DummyHook
def call(klass, method, dto:); end
end

describe HookConfiguration do
describe CaptainHook::Configuration do
let(:hook) { DummyHook.new }
let(:args) { {} }
let(:kwargs) { {} }
Expand All @@ -17,7 +17,7 @@ def call(klass, method, dto:); end
let(:skip_when) { nil }

subject do
HookConfiguration.new(
described_class.new(
hook: hook,
include: include,
exclude: [excluded_method],
Expand Down
Loading