interactor-extended 0.1.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.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/.rubocop.yml +28 -0
  4. data/CHANGELOG.md +5 -0
  5. data/CODE_OF_CONDUCT.md +84 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +86 -0
  8. data/Rakefile +12 -0
  9. data/VERSION +1 -0
  10. data/docs/colorize.md +22 -0
  11. data/docs/configuration.md +63 -0
  12. data/docs/context_definition.md +21 -0
  13. data/docs/duration.md +37 -0
  14. data/docs/flow.md +25 -0
  15. data/docs/jobify.md +38 -0
  16. data/docs/light_context.md +24 -0
  17. data/docs/light_context_definition.md +19 -0
  18. data/docs/loggable.md +17 -0
  19. data/docs/operation.md +34 -0
  20. data/docs/organize.md +20 -0
  21. data/docs/populate.md +34 -0
  22. data/lib/interactor/colorize.rb +61 -0
  23. data/lib/interactor/context_definition.rb +156 -0
  24. data/lib/interactor/contextable.rb +18 -0
  25. data/lib/interactor/duration/base_formatter.rb +32 -0
  26. data/lib/interactor/duration/color_string_formatter.rb +22 -0
  27. data/lib/interactor/duration/json_formatter.rb +43 -0
  28. data/lib/interactor/duration/string_formatter.rb +57 -0
  29. data/lib/interactor/duration.rb +97 -0
  30. data/lib/interactor/extended/configuration.rb +51 -0
  31. data/lib/interactor/extended/error.rb +8 -0
  32. data/lib/interactor/extended/helpers.rb +54 -0
  33. data/lib/interactor/extended/version.rb +30 -0
  34. data/lib/interactor/extended.rb +84 -0
  35. data/lib/interactor/flow.rb +21 -0
  36. data/lib/interactor/jobify.rb +121 -0
  37. data/lib/interactor/light_context.rb +169 -0
  38. data/lib/interactor/light_context_definition.rb +53 -0
  39. data/lib/interactor/loggable.rb +28 -0
  40. data/lib/interactor/operation.rb +21 -0
  41. data/lib/interactor/organize.rb +49 -0
  42. data/lib/interactor/populate.rb +63 -0
  43. data/lib/interactor/threadable.rb +13 -0
  44. data/sig/interactor/colorize.rbs +9 -0
  45. data/sig/interactor/context_definition.rbs +20 -0
  46. data/sig/interactor/contextable.rbs +6 -0
  47. data/sig/interactor/duration/base_formatter.rbs +12 -0
  48. data/sig/interactor/duration/color_string_formatter.rbs +9 -0
  49. data/sig/interactor/duration/json_formatter.rbs +7 -0
  50. data/sig/interactor/duration/string_formatter.rbs +7 -0
  51. data/sig/interactor/duration.rbs +7 -0
  52. data/sig/interactor/extended/configuration.rbs +14 -0
  53. data/sig/interactor/extended/error.rbs +6 -0
  54. data/sig/interactor/extended/helpers.rbs +9 -0
  55. data/sig/interactor/extended/version.rbs +10 -0
  56. data/sig/interactor/extended.rbs +12 -0
  57. data/sig/interactor/flow.rbs +8 -0
  58. data/sig/interactor/jobify.rbs +32 -0
  59. data/sig/interactor/light_context.rbs +28 -0
  60. data/sig/interactor/light_context_definition.rbs +13 -0
  61. data/sig/interactor/loggable.rbs +13 -0
  62. data/sig/interactor/operation.rbs +8 -0
  63. data/sig/interactor/organize.rbs +21 -0
  64. data/sig/interactor/populate.rbs +20 -0
  65. data/sig/interactor/threadable.rbs +5 -0
  66. metadata +127 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b5385744e8c2e5ec55ee5003c1d0052ea4d4ee1bd637e9b3257eb8c52b77ce96
4
+ data.tar.gz: b49f5f6edc03cf2e7029f881968f3352941d0b80a18c8266999fa6a43aaf96cd
5
+ SHA512:
6
+ metadata.gz: 6608cac5941d6792a7664323e1b4ecfbf5877d05cdf1c197b1aa3e14a6f955a4d6e77fdbdb54b4651d9f842c20e7b6f59707f2c2d9276517744ed6c7e0f69fdd
7
+ data.tar.gz: 2e0c6ce5ca3b23f3ce8cd194347d11047ad12a38f89c9f32a4cba82921c7d110f619b26e7dc9bb1e086e5a4cae81b7044f812ed4fc9129d608385ca7af8cd5a3
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,28 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ TargetRubyVersion: 3.2.2
4
+ SuggestExtensions: false
5
+ Exclude:
6
+ - 'vendor/**/*'
7
+ - 'zzz/**/*'
8
+
9
+ Style/Documentation:
10
+ Description: 'Document classes and non-namespace modules.'
11
+ Enabled: false
12
+ VersionAdded: '0.9'
13
+ AllowedConstants: []
14
+ Exclude:
15
+ - 'spec/**/*'
16
+ - 'test/**/*'
17
+
18
+ Metrics/MethodLength:
19
+ Enabled: false
20
+
21
+ Metrics/AbcSize:
22
+ Enabled: false
23
+
24
+ Metrics/BlockLength:
25
+ AllowedMethods: ['describe', 'context']
26
+ Exclude:
27
+ - 'spec/**/*'
28
+ - '*.gemspec'
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-04-24
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at prizrack13@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Anatolii Varanytsia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # Interactor::Extended
2
+
3
+ [![Quality Checks](https://github.com/Prizrack13/interactor-extended/actions/workflows/pull-requests.yml/badge.svg)](https://github.com/Prizrack13/interactor-extended/actions/workflows/pull-requests.yml)
4
+
5
+ A powerful extension for the `interactor` gem, providing a set of modules. Lightweight context, self-documented input/output attributes, logging, job integration, duration tracking debug, and more.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'interactor-extended'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```bash
18
+ $ bundle install
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```bash
24
+ $ gem install interactor-extended
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```ruby
30
+ class MyInteractor
31
+ include Interactor::Operation
32
+
33
+ input :id, Integer, require: true
34
+ output :user, User
35
+
36
+ def call
37
+ logger.info "Processing user: #{id}"
38
+ self.user = User.find(id)
39
+ rescue ActiveRecord::RecordNotFound
40
+ context.fail!(error: 'User not found')
41
+ end
42
+ end
43
+
44
+ result = MyInteractor.call(id: 1)
45
+ result.success? # => true
46
+ result.user # => #<User ...>
47
+ ```
48
+
49
+ ## Documentation
50
+
51
+ ### Core Modules
52
+ - [Operation](docs/operation.md)
53
+ - [Flow](docs/flow.md)
54
+ - [Organize](docs/organize.md)
55
+ - [LightContext](docs/light_context.md)
56
+ - [ContextDefinition & Contextable](docs/context_definition.md)
57
+
58
+ ### Extensions & Utilities
59
+ - [Duration](docs/duration.md)
60
+ - [Loggable](docs/loggable.md)
61
+ - [Jobify](docs/jobify.md)
62
+ - [Populate](docs/populate.md)
63
+ - [Extended](docs/extended.md)
64
+ - [Colorize](docs/colorize.md)
65
+
66
+ ### Additional Guides
67
+ - [Configuration](docs/configuration.md)
68
+ - [Best Practices](docs/best_practices.md)
69
+
70
+ ## Development
71
+
72
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
73
+
74
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
75
+
76
+ ## Contributing
77
+
78
+ Bug reports and pull requests are welcome on GitHub at https://github.com/prizrack13/interactor-extended. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/prizrack13/interactor-extended/blob/master/CODE_OF_CONDUCT.md).
79
+
80
+ ## License
81
+
82
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
83
+
84
+ ## Code of Conduct
85
+
86
+ Everyone interacting in the Interactor::Extended project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/prizrack13/interactor-extended/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/docs/colorize.md ADDED
@@ -0,0 +1,22 @@
1
+ # Interactor::Colorize
2
+
3
+ Provides ANSI color codes for terminal output. Used internally by `ColorStringFormatter` but available for custom logging.
4
+
5
+ **Example:**
6
+ ```ruby
7
+ require 'interactor/colorize'
8
+
9
+ puts Interactor::Colorize.colorize('Success', :green)
10
+ puts Interactor::Colorize.colorize('Warning', :yellow)
11
+ puts Interactor::Colorize.colorize('Error', :red)
12
+
13
+ class SimpleInteractor
14
+ include Interactor::Operation
15
+
16
+ def call
17
+ puts colorize('Success', :green)
18
+ end
19
+ end
20
+ ```
21
+
22
+ [Back to README](../README.md)
@@ -0,0 +1,63 @@
1
+ # Configuration
2
+
3
+ Global configuration can be set via `Interactor::Extended.configure`. This is typically done during application boot.
4
+
5
+ ```ruby
6
+ Interactor::Extended.configure do |config|
7
+ config.logger = Rails.logger
8
+ config.type = :light # Options: :ctx, :light, :legacy, :all, :all_debug
9
+ # config.type = [Interactor::Contextable]
10
+ config.duration_format = :json # Options: :json, :string, :color_string
11
+ config.on_duration = ->(duration) { print duration }
12
+ end
13
+ ```
14
+
15
+ ## Types
16
+ By default, including `Interactor::Operation` includes the full list of modules.
17
+ You can use a predefined set or create your own list.
18
+
19
+ ```ruby
20
+ # Also you can include in a specific class another set
21
+ # include ::Interactor::Operation[:light]
22
+ # for example you need high performance class
23
+ # include ::Interactor::Operation[:base] # just base
24
+
25
+ TYPES = {
26
+ base: [], # no extensions just Interactor or Flow
27
+ ctx: [::Interactor::Contextable], # improved context.
28
+ light: [ # Core set with light context definition
29
+ ::Interactor::Contextable,
30
+ ::Interactor::LightContextDefinition,
31
+ ::Interactor::Populate,
32
+ ::Interactor::Organize
33
+ ],
34
+ legacy: [ # Base set with context validation and default + jobify
35
+ ::Interactor::Contextable,
36
+ ::Interactor::ContextDefinition,
37
+ ::Interactor::Populate,
38
+ ::Interactor::Organize,
39
+ ::Interactor::Jobify
40
+ ],
41
+ all: [ # all modules
42
+ ::Interactor::Contextable,
43
+ ::Interactor::ContextDefinition,
44
+ ::Interactor::Populate,
45
+ ::Interactor::Organize,
46
+ ::Interactor::Jobify,
47
+ ::Interactor::Colorize,
48
+ ::Interactor::Loggable
49
+ ],
50
+ all_debug: [ # all modules + modules good for debug
51
+ ::Interactor::Contextable,
52
+ ::Interactor::ContextDefinition,
53
+ ::Interactor::Populate,
54
+ ::Interactor::Organize,
55
+ ::Interactor::Jobify,
56
+ ::Interactor::Colorize,
57
+ ::Interactor::Loggable,
58
+ ::Interactor::Duration
59
+ ]
60
+ }
61
+ ```
62
+
63
+ [Back to README](../README.md)
@@ -0,0 +1,21 @@
1
+ # Interactor::ContextDefinition
2
+
3
+ Provides type-safe input/output definitions with validation, requirement checks, and array handling.
4
+ It creates read/write methods and avoid OpenStruct performance issues. Since it is use context[].
5
+
6
+ **Example:**
7
+ ```ruby
8
+ class TypedInteractor
9
+ include Interactor::Operation
10
+
11
+ input :a, Integer
12
+ input :b, String, require: true
13
+ output :c, [Integer, String], array: true
14
+ def call
15
+ # Validation automatically checks types and requirements
16
+ self.c = [a, b]
17
+ end
18
+ end
19
+ ```
20
+
21
+ [Back to README](../README.md)
data/docs/duration.md ADDED
@@ -0,0 +1,37 @@
1
+ # Interactor::Duration
2
+
3
+ Tracks execution time for each interactor in a flow. Supports multiple formatters for output customization.
4
+
5
+ **Formatters:**
6
+ - :json => `JsonFormatter`: Returns JSON-compatible array of hashes.
7
+ - :string => `StringFormatter`: Returns a plain text table.
8
+ - :color_string => `ColorStringFormatter`: Returns an ANSI-colored string for terminal output.
9
+
10
+ **Configuration:**
11
+ ```ruby
12
+ Interactor::Extended.configure do
13
+ _1.duration_format = :color_string
14
+ _1.on_duration = ->(duration) { puts duration }
15
+ end
16
+ ```
17
+
18
+ Also you can do benchmark of methods by calling duration before method or duration(true) to track all methods in class.
19
+ ```
20
+ class Operation
21
+ include Interactor::Operation
22
+
23
+ duration # or duration(true)
24
+ def call
25
+ ...
26
+ end
27
+ end
28
+ ```
29
+
30
+ **Example Output:**
31
+ ```
32
+ - Flow count: 1 time: 53040.76 own: 27358.89
33
+ - Operation count: 2771 time: 9.27 own: 9.27
34
+ - Operation#call count: 2771 time: 9.27 own: 9.27
35
+ ```
36
+
37
+ [Back to README](../README.md)
data/docs/flow.md ADDED
@@ -0,0 +1,25 @@
1
+ # Interactor::Flow
2
+
3
+ Allows chaining multiple interactors sequentially. The context is passed from one interactor to the next, enabling complex workflows.
4
+
5
+ **Example:**
6
+ ```ruby
7
+ class SimpleSecondInteractor
8
+ include Interactor::Operation
9
+
10
+ def call
11
+ p context.data # Receives data from SimpleInteractor
12
+ end
13
+ end
14
+
15
+ class SimpleFlow
16
+ include Interactor::Flow
17
+
18
+ organize SimpleInteractor, SimpleSecondInteractor
19
+ end
20
+
21
+ # Runs both interactors in sequence
22
+ SimpleFlow.call!(a: 2)
23
+ ```
24
+
25
+ [Back to README](../README.md)
data/docs/jobify.md ADDED
@@ -0,0 +1,38 @@
1
+ # Interactor::Jobify
2
+
3
+ Integrates interactors with background job queues (e.g., Sidekiq, ActiveJob). Allows conditional async execution.
4
+
5
+ **Example:**
6
+ ```ruby
7
+ class UserInteractorJob < AsyncJob
8
+ queue_as :default
9
+
10
+ def perform(params)
11
+ user = User.find(params[:user_id])
12
+ ::UserInteractor.call!(user: user)
13
+ end
14
+ end
15
+
16
+ class UserInteractor
17
+ include Interactor::Operation
18
+
19
+ # you can pass klass name
20
+ # jobify(klass: AnotherJob)
21
+ # jobify(default: true) # it jobify by default
22
+ jobify { |interactor| { user_id: interactor.user.id } }
23
+
24
+ input :user, User
25
+
26
+ def call
27
+ logger.debug "Processing user: #{user.email}"
28
+ end
29
+ end
30
+
31
+ # Synchronous execution
32
+ UserInteractor.call!(user: User.first)
33
+
34
+ # Asynchronous execution
35
+ UserInteractor.call!(user: User.first, jobify: true)
36
+ ```
37
+
38
+ [Back to README](../README.md)
@@ -0,0 +1,24 @@
1
+ # Interactor::LightContext
2
+
3
+ A lightweight, `BasicObject`-based context implementation. It minimizes overhead and is ideal for high-performance scenarios where standard context features are unnecessary. Unlike the standard context, it does not inherit from `Struct` or `OpenStruct`, but instead delegates attribute access to an underlying hash.
4
+
5
+ **Key Features:**
6
+ - Extremely low memory footprint
7
+ - Fast attribute access via `method_missing` delegation
8
+ - Compatible with standard interactor workflows
9
+
10
+ **Example:**
11
+ ```ruby
12
+ class FastInteractor
13
+ include Interactor::Operation
14
+
15
+ def call
16
+ context.value = 42
17
+ end
18
+ end
19
+ ```
20
+
21
+ **Note:** Because `LightContext` inherits from `BasicObject`, it lacks many standard Ruby object methods. It relies on `respond_to_missing?` and `method_missing` to provide context-like behavior. Use it when performance is critical and you don't need the full context API.
22
+ In most cases you should use context[:value] for better performance.
23
+
24
+ [Back to README](../README.md)
@@ -0,0 +1,19 @@
1
+ # Interactor::LightContextDefinition
2
+
3
+ It similar to Interactor::ContextDefinition but it basically creates only read/write methods.
4
+
5
+ **Example:**
6
+ ```ruby
7
+ class TypedInteractor
8
+ include Interactor::Operation
9
+
10
+ input :a, Integer
11
+ input :b, String, require: true
12
+ output :c, [Integer, String], array: true
13
+ def call
14
+ self.c = [a, b]
15
+ end
16
+ end
17
+ ```
18
+
19
+ [Back to Table of Contents](../interactors.md)
data/docs/loggable.md ADDED
@@ -0,0 +1,17 @@
1
+ # Interactor::Loggable
2
+
3
+ Adds a logger instance to the interactor context. Automatically configures log levels and formatting.
4
+
5
+ **Example:**
6
+ ```ruby
7
+ class LoggedInteractor
8
+ include Interactor::Operation
9
+
10
+ def call
11
+ logger.debug "Processing context: #{context.inspect}"
12
+ logger.info "Completed successfully"
13
+ end
14
+ end
15
+ ```
16
+
17
+ [Back to README](../README.md)
data/docs/operation.md ADDED
@@ -0,0 +1,34 @@
1
+ # Interactor::Operation
2
+
3
+ The foundational module for creating interactors. It provides context management, success/failure handling, and integrates seamlessly with other extensions.
4
+
5
+ **Example:**
6
+ ```ruby
7
+ class SimpleInteractor
8
+ include Interactor::Operation
9
+
10
+ def call
11
+ # Access context values
12
+ p context.a
13
+
14
+ # Fail the interactor if validation fails
15
+ context.fail!(error: 'Invalid input') unless context.a.is_a?(Integer)
16
+
17
+ # Set output values
18
+ context.data = context.a * 2
19
+ end
20
+ end
21
+
22
+ # Execution
23
+ result = SimpleInteractor.call(a: 1)
24
+ result.success? # => true
25
+ result.data # => 2
26
+
27
+ result = SimpleInteractor.call(a: '')
28
+ result.success? # => false
29
+
30
+ # Raises Interactor::Failure if not successful
31
+ SimpleInteractor.call!(a: '')
32
+ ```
33
+
34
+ [Back to README](../README.md)
data/docs/organize.md ADDED
@@ -0,0 +1,20 @@
1
+ # Interactor::Organize
2
+
3
+ It adds useful methods.
4
+ With organize key you can run only specific interactors.
5
+ Also, you can run interactos in parallel way using thread method.
6
+
7
+ **Example:**
8
+ ```ruby
9
+ class ParallelFlow
10
+ include Interactor::Flow
11
+
12
+ organize(
13
+ thread(SimpleInteractor),
14
+ thread(SimpleSecondInteractor)
15
+ )
16
+ end
17
+ ParallelFlow.call!(organize: [SimpleInteractor])
18
+ ```
19
+
20
+ [Back to README](../README.md)
data/docs/populate.md ADDED
@@ -0,0 +1,34 @@
1
+ # Interactor::Populate
2
+
3
+ Enables selective context passing between interactors. Useful when you want to copy/update specific keys in the parent context.
4
+ By default, it copies all keys started with underscore.
5
+
6
+ **Example:**
7
+ ```ruby
8
+ class AnotherInteractor
9
+ include Interactor::Operation
10
+
11
+ input :a
12
+ output :c
13
+ def call
14
+ self.c = a * 2
15
+ end
16
+ end
17
+
18
+ class SimpleInteractor
19
+ include Interactor::Operation
20
+
21
+ input :a
22
+ input :b
23
+ def call
24
+ AnotherInteractor.call!(context) # it will populate all context
25
+ p b
26
+ AnotherInteractor.call!({ a: a * 2 }, context, :c)
27
+ p context.c
28
+ # or
29
+ # AnotherInteractor.call!(a: a * 2, context: context, context_keys: %i[c])
30
+ end
31
+ end
32
+ ```
33
+
34
+ [Back to README](../README.md)