-
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.
implement Interactify.with job configuration DSL (#37)
- Loading branch information
Showing
19 changed files
with
419 additions
and
85 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
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
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,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module Interactify | ||
module Core | ||
extend ActiveSupport::Concern | ||
|
||
included do |base| | ||
base.extend Interactify::Dsl | ||
|
||
base.include Interactor::Organizer | ||
base.include Interactor::Contracts | ||
base.include Interactify::Contracts::Helpers | ||
end | ||
|
||
def called_klass_list | ||
context._called.map(&:class) | ||
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,52 @@ | ||
# frozen_string_literal: true | ||
|
||
require "interactify/core" | ||
require "interactify/async/jobable" | ||
|
||
module Interactify | ||
class WithOptions | ||
def initialize(receiver, sidekiq_opts = {}) | ||
@receiver = receiver | ||
@options = sidekiq_opts.transform_keys(&:to_sym) | ||
end | ||
|
||
def setup | ||
validate_options | ||
|
||
this = self | ||
|
||
@receiver.instance_eval do | ||
include Interactify::Core | ||
include Interactify::Async::Jobable | ||
interactor_job(opts: this.options, klass_suffix: this.klass_suffix) | ||
|
||
# define aliases when the generate class name differs. | ||
# i.e. when options are passed | ||
if this.klass_suffix.present? | ||
const_set("Job", const_get(:"Job#{this.klass_suffix}")) | ||
const_set("Async", const_get(:"Async#{this.klass_suffix}")) | ||
end | ||
end | ||
end | ||
|
||
attr_reader :options | ||
|
||
def klass_suffix | ||
@klass_suffix ||= options.keys.sort.map do |key| | ||
"__#{key.to_s.camelize}_#{options[key].to_s.camelize}" | ||
end.join | ||
end | ||
|
||
private | ||
|
||
def validate_options | ||
return if invalid_keys.none? | ||
|
||
raise ArgumentError, "Invalid keys: #{invalid_keys}" | ||
end | ||
|
||
def invalid_keys | ||
options.keys - Interactify::Async::JobMaker::VALID_KEYS | ||
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
Oops, something went wrong.