-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract modules to make code structure more apparent
- Loading branch information
Showing
6 changed files
with
132 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Interactify | ||
module Configure | ||
def validate_app(ignore: []) | ||
Interactify::Wiring.new(root: Interactify.configuration.root, ignore:).validate_app | ||
end | ||
|
||
def configure | ||
yield configuration | ||
end | ||
|
||
def configuration | ||
@configuration ||= Configuration.new | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Interactify | ||
module Breaches | ||
def self.handle_with_failure(context, breaches) | ||
breaches = preamble(context, breaches) | ||
context.fail! contract_failures: breaches | ||
end | ||
|
||
def self.handle_with_exception(context, failure_klass, breaches) | ||
breaches = preamble(context, breaches) | ||
|
||
# e.g. raises | ||
# SomeNamespace::SomeClass::ContractFailure, {whatever: 'is missing'} | ||
# but also sending the context into Sentry | ||
exception = failure_klass.new(breaches.to_json) | ||
Interactify.trigger_before_raise_hook(exception) | ||
raise exception | ||
end | ||
|
||
def self.preamble(context, breaches) | ||
breaches = breaches.map { |b| { b.property => b.messages } }.inject(&:merge) | ||
|
||
Interactify.trigger_contract_breach_hook(context, breaches) | ||
breaches | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module Interactify | ||
class << self | ||
delegate :on_definition_error, :trigger_definition_error, to: :configuration | ||
|
||
def railties_missing? | ||
@railties_missing | ||
end | ||
|
||
def railties_missing! | ||
@railties_missing = true | ||
end | ||
|
||
def railties | ||
railties? | ||
end | ||
|
||
def railties? | ||
!railties_missing? | ||
end | ||
|
||
def sidekiq_missing? | ||
@sidekiq_missing | ||
end | ||
|
||
def sidekiq_missing! | ||
@sidekiq_missing = true | ||
end | ||
|
||
def sidekiq | ||
sidekiq? | ||
end | ||
|
||
def sidekiq? | ||
!sidekiq_missing? | ||
end | ||
end | ||
end | ||
|
||
Interactify.instance_eval do | ||
@sidekiq_missing = nil | ||
@railties_missing = nil | ||
end | ||
|
||
begin | ||
require "sidekiq" | ||
rescue LoadError | ||
Interactify.sidekiq_missing! | ||
end | ||
|
||
begin | ||
require "rails/railtie" | ||
rescue LoadError | ||
Interactify.railties_missing! | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Interactify | ||
module Hooks | ||
def reset | ||
@on_contract_breach = nil | ||
@before_raise_hook = nil | ||
@configuration = nil | ||
end | ||
|
||
def trigger_contract_breach_hook(...) | ||
@on_contract_breach&.call(...) | ||
end | ||
|
||
def on_contract_breach(&block) | ||
@on_contract_breach = block | ||
end | ||
|
||
def trigger_before_raise_hook(...) | ||
@before_raise_hook&.call(...) | ||
end | ||
|
||
def before_raise(&block) | ||
@before_raise_hook = block | ||
end | ||
end | ||
end |