activeinteractor 1.2.2 → 2.0.0.alpha.1.0.0
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 +4 -4
- data/CHANGELOG.md +1 -1
- data/LICENSE +1 -1
- data/README.md +4 -64
- data/lib/active_interactor/base.rb +77 -29
- data/lib/active_interactor/errors.rb +12 -0
- data/lib/active_interactor/result.rb +73 -0
- data/lib/active_interactor.rb +3 -101
- data/sig/active_interactor.rbs +3 -0
- metadata +23 -86
- data/.yardopts +0 -12
- data/lib/active_interactor/config.rb +0 -60
- data/lib/active_interactor/configurable.rb +0 -53
- data/lib/active_interactor/context/attributes.rb +0 -179
- data/lib/active_interactor/context/base.rb +0 -333
- data/lib/active_interactor/context/errors.rb +0 -57
- data/lib/active_interactor/context/loader.rb +0 -50
- data/lib/active_interactor/context/status.rb +0 -106
- data/lib/active_interactor/error.rb +0 -46
- data/lib/active_interactor/interactor/callbacks.rb +0 -293
- data/lib/active_interactor/interactor/context.rb +0 -378
- data/lib/active_interactor/interactor/perform.rb +0 -260
- data/lib/active_interactor/interactor/worker.rb +0 -120
- data/lib/active_interactor/models.rb +0 -50
- data/lib/active_interactor/organizer/base.rb +0 -18
- data/lib/active_interactor/organizer/callbacks.rb +0 -275
- data/lib/active_interactor/organizer/interactor_interface.rb +0 -127
- data/lib/active_interactor/organizer/interactor_interface_collection.rb +0 -62
- data/lib/active_interactor/organizer/organize.rb +0 -67
- data/lib/active_interactor/organizer/perform.rb +0 -112
- data/lib/active_interactor/rails/orm/active_record.rb +0 -5
- data/lib/active_interactor/rails/orm/dynamoid.rb +0 -5
- data/lib/active_interactor/rails/orm/mongoid.rb +0 -5
- data/lib/active_interactor/rails/railtie.rb +0 -21
- data/lib/active_interactor/rails.rb +0 -4
- data/lib/active_interactor/version.rb +0 -45
- data/lib/rails/generators/active_interactor/application_context_generator.rb +0 -21
- data/lib/rails/generators/active_interactor/application_interactor_generator.rb +0 -21
- data/lib/rails/generators/active_interactor/application_organizer_generator.rb +0 -21
- data/lib/rails/generators/active_interactor/base.rb +0 -29
- data/lib/rails/generators/active_interactor/generator.rb +0 -21
- data/lib/rails/generators/active_interactor/install_generator.rb +0 -16
- data/lib/rails/generators/active_interactor.rb +0 -5
- data/lib/rails/generators/interactor/context/rspec_generator.rb +0 -17
- data/lib/rails/generators/interactor/context/test_unit_generator.rb +0 -17
- data/lib/rails/generators/interactor/context_generator.rb +0 -22
- data/lib/rails/generators/interactor/generates_context.rb +0 -28
- data/lib/rails/generators/interactor/interactor_generator.rb +0 -25
- data/lib/rails/generators/interactor/organizer_generator.rb +0 -39
- data/lib/rails/generators/interactor/rspec_generator.rb +0 -15
- data/lib/rails/generators/interactor/test_unit_generator.rb +0 -15
- data/lib/rails/generators/templates/active_interactor.erb +0 -17
- data/lib/rails/generators/templates/application_context.rb +0 -4
- data/lib/rails/generators/templates/application_interactor.rb +0 -4
- data/lib/rails/generators/templates/application_organizer.rb +0 -4
- data/lib/rails/generators/templates/context.erb +0 -7
- data/lib/rails/generators/templates/context_spec.erb +0 -7
- data/lib/rails/generators/templates/context_test_unit.erb +0 -9
- data/lib/rails/generators/templates/interactor.erb +0 -15
- data/lib/rails/generators/templates/interactor_spec.erb +0 -7
- data/lib/rails/generators/templates/interactor_test_unit.erb +0 -9
- data/lib/rails/generators/templates/organizer.erb +0 -13
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveInteractor
|
4
|
-
module Organizer
|
5
|
-
# Organizer organize methods. Because {Organize} is a module classes should include {Organize} rather than inherit
|
6
|
-
# from it.
|
7
|
-
#
|
8
|
-
# @author Aaron Allen <hello@aaronmallen.me>
|
9
|
-
# @since 1.0.0
|
10
|
-
module Organize
|
11
|
-
# Organizer organize class methods. Because {ClassMethods} is a module classes should extend {ClassMethods}
|
12
|
-
# rather than inherit from it.
|
13
|
-
#
|
14
|
-
# @author Aaron Allen <hello@aaronmallen.me>
|
15
|
-
# @since 1.0.0
|
16
|
-
module ClassMethods
|
17
|
-
# {#organized Organize} {ActiveInteractor::Base interactors} to be called by the {Base organizer}.
|
18
|
-
# A block will be evaluated on the {#organized InteractorInterfaceCollection} if a block is given.
|
19
|
-
#
|
20
|
-
# @since 0.1.0
|
21
|
-
#
|
22
|
-
# @example Basic organization of {ActiveInteractor::Base interactors}
|
23
|
-
# class MyInteractor1 < ActiveInteractor::Base; end
|
24
|
-
# class MyInteractor2 < ActiveInteractor::Base; end
|
25
|
-
# class MyOrganizer < ActiveInteractor::Organizer::Base
|
26
|
-
# organize :my_interactor_1, :my_interactor_2
|
27
|
-
# end
|
28
|
-
#
|
29
|
-
# @example Conditional organization of {ActiveInteractor::Base interactors}
|
30
|
-
# class MyInteractor1 < ActiveInteractor::Base; end
|
31
|
-
# class MyInteractor2 < ActiveInteractor::Base; end
|
32
|
-
# class MyOrganizer < ActiveInteractor::Organizer::Base
|
33
|
-
# organize do
|
34
|
-
# add :my_interactor_1
|
35
|
-
# add :my_interactor_2, if: -> { context.valid? }
|
36
|
-
# end
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
# @example organization of {ActiveInteractor::Base interactors} with {Interactor::Perform::Options options}
|
40
|
-
# class MyInteractor1 < ActiveInteractor::Base; end
|
41
|
-
# class MyInteractor2 < ActiveInteractor::Base; end
|
42
|
-
# class MyOrganizer < ActiveInteractor::Organizer::Base
|
43
|
-
# organize do
|
44
|
-
# add :my_interactor_1, validate: false
|
45
|
-
# add :my_interactor_2, skip_perform_callbacks: true
|
46
|
-
# end
|
47
|
-
# end
|
48
|
-
#
|
49
|
-
# @param interactors [Array<Const, Symbol, String>, nil] the {ActiveInteractor::Base} interactor classes to be
|
50
|
-
# {#organized organized}
|
51
|
-
# @return [InteractorInterfaceCollection] the {#organized} {ActiveInteractor::Base interactors}
|
52
|
-
def organize(*interactors, &block)
|
53
|
-
organized.concat(interactors) if interactors
|
54
|
-
organized.instance_eval(&block) if block
|
55
|
-
organized
|
56
|
-
end
|
57
|
-
|
58
|
-
# An organized collection of {ActiveInteractor::Base interactors}
|
59
|
-
#
|
60
|
-
# @return [InteractorInterfaceCollection] an instance of {InteractorInterfaceCollection}
|
61
|
-
def organized
|
62
|
-
@organized ||= ActiveInteractor::Organizer::InteractorInterfaceCollection.new
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,112 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveInteractor
|
4
|
-
module Organizer
|
5
|
-
# Organizer perform methods. Because {Perform} is a module classes should include {Perform} rather than inherit
|
6
|
-
# from it.
|
7
|
-
#
|
8
|
-
# @author Aaron Allen <hello@aaronmallen.me>
|
9
|
-
# @since 1.0.0
|
10
|
-
module Perform
|
11
|
-
# Organizer perform class methods. Because {ClassMethods} is a module classes should extend {ClassMethods}
|
12
|
-
# rather than inherit from it.
|
13
|
-
#
|
14
|
-
# @author Aaron Allen <hello@aaronmallen.me>
|
15
|
-
# @since 1.0.0
|
16
|
-
#
|
17
|
-
# @!attribute [r] parallel
|
18
|
-
# If `true` the {Base organizer} will call {Interactor::Perform#perform #perform} on its
|
19
|
-
# {Organizer::Organize::ClassMethods#organize .organized} {ActiveInteractor::Base interactors} in parallel.
|
20
|
-
# An {Base organizer} will have {.parallel} `false` by default.
|
21
|
-
#
|
22
|
-
# @!scope class
|
23
|
-
# @since 1.0.0
|
24
|
-
#
|
25
|
-
# @return [Boolean] whether or not to call {Interactor::Perform#perform #perform} on its
|
26
|
-
# {Organizer::Organize::ClassMethods#organize .organized} {ActiveInteractor::Base interactors} in parallel.
|
27
|
-
module ClassMethods
|
28
|
-
# Set {.parallel} to `true`
|
29
|
-
#
|
30
|
-
# @example a basic {Base organizer} set to perform in parallel
|
31
|
-
# class MyOrganizer < ActiveInteractor::Organizer::Base
|
32
|
-
# perform_in_parallel
|
33
|
-
# end
|
34
|
-
def perform_in_parallel
|
35
|
-
self.parallel = true
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.included(base)
|
40
|
-
base.class_eval do
|
41
|
-
class_attribute :parallel, instance_writer: false, default: false
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Call the {Organize::ClassMethods#organized .organized} {ActiveInteractor::Base interactors}
|
46
|
-
# {Interactor::Perform#perform #perform}. An {Base organizer} is expected not to define its own
|
47
|
-
# {Interactor::Perform#perform #perform} method in favor of this default implementation.
|
48
|
-
def perform
|
49
|
-
run_callbacks :all_perform do
|
50
|
-
if self.class.parallel
|
51
|
-
perform_in_parallel
|
52
|
-
else
|
53
|
-
perform_in_order
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def run_deferred_after_perform_callbacks_on_children
|
59
|
-
self.class.organized.each do |interface|
|
60
|
-
next unless interface.interactor_class.after_callbacks_deferred_when_organized
|
61
|
-
|
62
|
-
context.merge!(interface.execute_deferred_after_perform_callbacks(context))
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
private
|
67
|
-
|
68
|
-
def execute_interactor(interface, fail_on_error = false, perform_options = {})
|
69
|
-
interface.perform(self, context, fail_on_error, perform_options)
|
70
|
-
end
|
71
|
-
|
72
|
-
def execute_interactor_with_callbacks(interface, fail_on_error = false, perform_options = {})
|
73
|
-
args = [interface, fail_on_error, perform_options]
|
74
|
-
return execute_interactor(*args) if options.skip_each_perform_callbacks
|
75
|
-
|
76
|
-
run_callbacks :each_perform do
|
77
|
-
execute_interactor(*args)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def merge_contexts(contexts)
|
82
|
-
contexts.each { |context| @context.merge!(context) }
|
83
|
-
context_fail! if contexts.any?(&:failure?)
|
84
|
-
end
|
85
|
-
|
86
|
-
def execute_and_merge_contexts(interface)
|
87
|
-
interface.execute_inplace_callback(self, :before)
|
88
|
-
result = execute_interactor_with_callbacks(interface, true)
|
89
|
-
return if result.nil?
|
90
|
-
|
91
|
-
context.merge!(result)
|
92
|
-
context_fail! if result.failure?
|
93
|
-
interface.execute_inplace_callback(self, :after)
|
94
|
-
end
|
95
|
-
|
96
|
-
def perform_in_order
|
97
|
-
self.class.organized.each do |interface|
|
98
|
-
execute_and_merge_contexts(interface)
|
99
|
-
end
|
100
|
-
rescue ActiveInteractor::Error::ContextFailure => e
|
101
|
-
context.merge!(e.context)
|
102
|
-
end
|
103
|
-
|
104
|
-
def perform_in_parallel
|
105
|
-
results = self.class.organized.map do |interface|
|
106
|
-
Thread.new { execute_interactor_with_callbacks(interface, false, skip_rollback: true) }
|
107
|
-
end
|
108
|
-
merge_contexts(results.map(&:value))
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails'
|
4
|
-
|
5
|
-
module ActiveInteractor
|
6
|
-
# Rails classes and modules.
|
7
|
-
#
|
8
|
-
# @author Aaron Allen <hello@aaronmallen.me>
|
9
|
-
# @since 1.0.0
|
10
|
-
module Rails
|
11
|
-
# The ActiveInteractor Railtie
|
12
|
-
#
|
13
|
-
# @author Aaron Allen <hello@aaronmallen.me>
|
14
|
-
# @since 1.0.0
|
15
|
-
#
|
16
|
-
# @see https://api.rubyonrails.org/classes/Rails/Railtie.html
|
17
|
-
class Railtie < ::Rails::Railtie
|
18
|
-
config.eager_load_namespaces << ActiveInteractor
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveInteractor
|
4
|
-
# The ActiveInteractor version info
|
5
|
-
#
|
6
|
-
# @author Aaron Allen <hello@aaronmallen.me>
|
7
|
-
# @since unreleased
|
8
|
-
module Version
|
9
|
-
# The ActiveInterctor major version number
|
10
|
-
# @return [Integer] The ActiveInteractor major version number
|
11
|
-
MAJOR = 1
|
12
|
-
|
13
|
-
# The ActiveInterctor minor version number
|
14
|
-
# @return [Integer] The ActiveInteractor minor version number
|
15
|
-
MINOR = 2
|
16
|
-
|
17
|
-
# The ActiveInterctor patch version number
|
18
|
-
# @return [Integer] The ActiveInteractor patch version number
|
19
|
-
PATCH = 2
|
20
|
-
|
21
|
-
# The ActiveInterctor pre-release version
|
22
|
-
# @return [String | nil] The ActiveInteractor pre-release version
|
23
|
-
PRE = nil
|
24
|
-
|
25
|
-
# The ActiveInterctor meta version
|
26
|
-
# @return [String | nil] The ActiveInteractor meta version
|
27
|
-
META = nil
|
28
|
-
|
29
|
-
# The ActiveInterctor rubygems version
|
30
|
-
# @return [String] The ActiveInteractor rubygems version
|
31
|
-
def self.gem_version
|
32
|
-
pre_meta = PRE.nil? ? nil : [PRE, META].compact.join('.').freeze
|
33
|
-
[MAJOR, MINOR, PATCH, pre_meta].compact.join('.').freeze
|
34
|
-
end
|
35
|
-
|
36
|
-
# The ActiveInterctor semver version
|
37
|
-
# @return [String] The ActiveInteractor semver version
|
38
|
-
def self.semver
|
39
|
-
version = [MAJOR, MINOR, PATCH].join('.')
|
40
|
-
version = "#{version}-#{PRE}" if PRE
|
41
|
-
version = "#{version}+#{META}" if META
|
42
|
-
version.freeze
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/generators/active_interactor/base'
|
4
|
-
|
5
|
-
module ActiveInteractor
|
6
|
-
module Generators
|
7
|
-
class ApplicationContextGenerator < Base
|
8
|
-
def create_application_organizer
|
9
|
-
return if File.exist?(file_path)
|
10
|
-
|
11
|
-
template 'application_context.rb', file_path
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def file_path
|
17
|
-
"app/#{active_interactor_directory}/application_context.rb"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/generators/active_interactor/base'
|
4
|
-
|
5
|
-
module ActiveInteractor
|
6
|
-
module Generators
|
7
|
-
class ApplicationInteractorGenerator < Base
|
8
|
-
def create_application_interactor
|
9
|
-
return if File.exist?(file_path)
|
10
|
-
|
11
|
-
template 'application_interactor.rb', file_path
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def file_path
|
17
|
-
"app/#{active_interactor_directory}/application_interactor.rb"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/generators/active_interactor/base'
|
4
|
-
|
5
|
-
module ActiveInteractor
|
6
|
-
module Generators
|
7
|
-
class ApplicationOrganizerGenerator < Base
|
8
|
-
def create_application_organizer
|
9
|
-
return if File.exist?(file_path)
|
10
|
-
|
11
|
-
template 'application_organizer.rb', file_path
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def file_path
|
17
|
-
"app/#{active_interactor_directory}/application_organizer.rb"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/generators'
|
4
|
-
|
5
|
-
require 'rails/generators/active_interactor/generator'
|
6
|
-
|
7
|
-
module ActiveInteractor
|
8
|
-
module Generators
|
9
|
-
class Base < ::Rails::Generators::Base
|
10
|
-
extend Generator
|
11
|
-
include Generator
|
12
|
-
end
|
13
|
-
|
14
|
-
class NamedBase < ::Rails::Generators::NamedBase
|
15
|
-
extend Generator
|
16
|
-
include Generator
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def active_interactor_file(parent_dir: 'app', suffix: nil)
|
21
|
-
File.join(parent_dir, active_interactor_directory, class_path, "#{file_name_with_suffix(suffix)}.rb")
|
22
|
-
end
|
23
|
-
|
24
|
-
def file_name_with_suffix(suffix)
|
25
|
-
suffix ? "#{file_name}_#{suffix}" : file_name
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveInteractor
|
4
|
-
module Generators
|
5
|
-
module Generator
|
6
|
-
def source_root
|
7
|
-
File.expand_path('../templates', __dir__)
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def active_interactor_directory
|
13
|
-
active_interactor_options.fetch(:dir, 'interactors')
|
14
|
-
end
|
15
|
-
|
16
|
-
def active_interactor_options
|
17
|
-
::Rails.application.config.generators.options.fetch(:active_interactor, {})
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/generators/active_interactor/base'
|
4
|
-
|
5
|
-
module ActiveInteractor
|
6
|
-
module Generators
|
7
|
-
class InstallGenerator < Base
|
8
|
-
desc 'Install ActiveInteractor'
|
9
|
-
class_option :orm
|
10
|
-
|
11
|
-
def create_initializer
|
12
|
-
template 'active_interactor.erb', File.join('config', 'initializers', 'active_interactor.rb')
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,5 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
Dir[File.expand_path('active_interactor/*.rb', __dir__)].sort.each { |file| require file }
|
4
|
-
Dir[File.expand_path('interactor/context/*.rb', __dir__)].sort.each { |file| require file }
|
5
|
-
Dir[File.expand_path('interactor/*.rb', __dir__)].sort.each { |file| require file }
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/generators/active_interactor/base'
|
4
|
-
|
5
|
-
module Interactor
|
6
|
-
module Context
|
7
|
-
module Generators
|
8
|
-
class RspecGenerator < ActiveInteractor::Generators::NamedBase
|
9
|
-
desc 'Generate an interactor context spec'
|
10
|
-
|
11
|
-
def create_spec
|
12
|
-
template 'context_spec.erb', active_interactor_file(parent_dir: 'spec', suffix: 'context_spec')
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/generators/active_interactor/base'
|
4
|
-
|
5
|
-
module Interactor
|
6
|
-
module Context
|
7
|
-
module Generators
|
8
|
-
class TestUnitGenerator < ActiveInteractor::Generators::NamedBase
|
9
|
-
desc 'Generate an interactor context unit test'
|
10
|
-
|
11
|
-
def create_spec
|
12
|
-
template 'context_test_unit.erb', active_interactor_file(parent_dir: 'test', suffix: 'context_test')
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/generators/active_interactor/base'
|
4
|
-
|
5
|
-
module Interactor
|
6
|
-
module Generators
|
7
|
-
class ContextGenerator < ActiveInteractor::Generators::NamedBase
|
8
|
-
desc 'Generate an interactor context'
|
9
|
-
argument :context_attributes, type: :array, default: [], banner: 'attribute attribute'
|
10
|
-
|
11
|
-
def generate_application_context
|
12
|
-
generate :'active_interactor:application_context'
|
13
|
-
end
|
14
|
-
|
15
|
-
def create_context
|
16
|
-
template 'context.erb', active_interactor_file(suffix: 'context')
|
17
|
-
end
|
18
|
-
|
19
|
-
hook_for :test_framework, in: :'interactor:context'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Interactor
|
4
|
-
module Generators
|
5
|
-
module GeneratesContext
|
6
|
-
module WithArguments
|
7
|
-
def self.included(base)
|
8
|
-
base.class_eval do
|
9
|
-
include GeneratesContext
|
10
|
-
argument :context_attributes, type: :array, default: [], banner: 'attribute attribute'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.included(base)
|
16
|
-
base.class_eval do
|
17
|
-
class_option :skip_context, type: :boolean, desc: 'Whether or not to generate a context class'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def skip_context?
|
24
|
-
options[:skip_context] == true || active_interactor_options.fetch(:generate_context, true) == false
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/generators/active_interactor/base'
|
4
|
-
require 'rails/generators/interactor/generates_context'
|
5
|
-
|
6
|
-
class InteractorGenerator < ActiveInteractor::Generators::NamedBase
|
7
|
-
include Interactor::Generators::GeneratesContext::WithArguments
|
8
|
-
desc 'Generate an interactor'
|
9
|
-
|
10
|
-
def generate_application_interactor
|
11
|
-
generate :'active_interactor:application_interactor'
|
12
|
-
end
|
13
|
-
|
14
|
-
def create_interactor
|
15
|
-
template 'interactor.erb', active_interactor_file
|
16
|
-
end
|
17
|
-
|
18
|
-
def create_context
|
19
|
-
return if skip_context?
|
20
|
-
|
21
|
-
generate :'interactor:context', class_name, *context_attributes
|
22
|
-
end
|
23
|
-
|
24
|
-
hook_for :test_framework, in: :interactor
|
25
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/generators/active_interactor/base'
|
4
|
-
require 'rails/generators/interactor/generates_context'
|
5
|
-
|
6
|
-
module Interactor
|
7
|
-
module Generators
|
8
|
-
class OrganizerGenerator < ActiveInteractor::Generators::NamedBase
|
9
|
-
include GeneratesContext
|
10
|
-
desc 'Generate an interactor organizer'
|
11
|
-
argument :interactors, type: :array, default: [], banner: 'interactor interactor'
|
12
|
-
|
13
|
-
class_option :context_attributes, type: :array, default: [], banner: 'attribute attribute',
|
14
|
-
desc: 'Attributes for the context'
|
15
|
-
|
16
|
-
def generate_application_organizer
|
17
|
-
generate :'active_interactor:application_organizer'
|
18
|
-
end
|
19
|
-
|
20
|
-
def create_organizer
|
21
|
-
template 'organizer.erb', active_interactor_file
|
22
|
-
end
|
23
|
-
|
24
|
-
def create_context
|
25
|
-
return if skip_context?
|
26
|
-
|
27
|
-
generate :'interactor:context', class_name, *context_attributes
|
28
|
-
end
|
29
|
-
|
30
|
-
hook_for :test_framework, in: :interactor
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def context_attributes
|
35
|
-
options[:context_attributes]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/generators/active_interactor/base'
|
4
|
-
|
5
|
-
module Interactor
|
6
|
-
module Generators
|
7
|
-
class RspecGenerator < ActiveInteractor::Generators::NamedBase
|
8
|
-
desc 'Generate an interactor spec'
|
9
|
-
|
10
|
-
def create_spec
|
11
|
-
template 'interactor_spec.erb', active_interactor_file(parent_dir: 'spec', suffix: 'spec')
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/generators/active_interactor/base'
|
4
|
-
|
5
|
-
module Interactor
|
6
|
-
module Generators
|
7
|
-
class TestUnitGenerator < ActiveInteractor::Generators::NamedBase
|
8
|
-
desc 'Generate an interactor unit test'
|
9
|
-
|
10
|
-
def create_spec
|
11
|
-
template 'interactor_test_unit.erb', active_interactor_file(parent_dir: 'test', suffix: 'test')
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'active_interactor'
|
4
|
-
|
5
|
-
ActiveInteractor.configure do |config|
|
6
|
-
# ORM configuration
|
7
|
-
# Load and configure the ORM. Supports :active_record (default)
|
8
|
-
# Other ORMs may be available as additional gems.
|
9
|
-
<%- if options[:orm] -%>
|
10
|
-
require 'active_interactor/rails/orm/<%= options[:orm] %>'
|
11
|
-
<%- else -%>
|
12
|
-
# require 'active_interactor/rails/orm/<MY_ORM>'
|
13
|
-
<%- end -%>
|
14
|
-
|
15
|
-
# Set the ActiveInteractor.logger
|
16
|
-
config.logger = ::Rails.logger
|
17
|
-
end
|