gaskit 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 730e79d1901d9f1387a4017012b826e8770721d54091c51ce39e06516fe79d02
4
+ data.tar.gz: 13d90e62fe463f95363a06fc23d006c6548684a7154e4694a4506c163100b5f6
5
+ SHA512:
6
+ metadata.gz: c79fab8c3710d603b82478efabe67bc137325590a1af10c65b6abb4d8c4936bdd52111e9c0901d2815acf3e6e4a7d226715d40e5a0e1f3cf4462d1946671e548
7
+ data.tar.gz: a54df89b8f1b9a32b8c86ab37b7cb9c0b6034dc8a113aa1f29dca36a871ab5300df7d27075962877299fc627735547719d5d95677d91c2a38deb35a813cf25a6
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rspec_status ADDED
@@ -0,0 +1,75 @@
1
+ example_id | status | run_time |
2
+ ---------------------------------------------- | ------ | --------------- |
3
+ ./spec/gaskit/configuration_spec.rb[1:1:1] | passed | 0.0011 seconds |
4
+ ./spec/gaskit/configuration_spec.rb[1:2:1] | passed | 0.00006 seconds |
5
+ ./spec/gaskit/configuration_spec.rb[1:2:2] | passed | 0.00004 seconds |
6
+ ./spec/gaskit/configuration_spec.rb[1:2:3] | passed | 0.00004 seconds |
7
+ ./spec/gaskit/configuration_spec.rb[1:2:4] | passed | 0.00003 seconds |
8
+ ./spec/gaskit/configuration_spec.rb[1:3:1] | passed | 0.00052 seconds |
9
+ ./spec/gaskit/configuration_spec.rb[1:4:1] | passed | 0.00004 seconds |
10
+ ./spec/gaskit/configuration_spec.rb[1:4:2] | passed | 0.00004 seconds |
11
+ ./spec/gaskit/configuration_spec.rb[1:5:1] | passed | 0.00005 seconds |
12
+ ./spec/gaskit/configuration_spec.rb[1:5:2] | passed | 0.00122 seconds |
13
+ ./spec/gaskit/contract_registry_spec.rb[1:1:1] | passed | 0.00006 seconds |
14
+ ./spec/gaskit/contract_registry_spec.rb[1:1:2] | passed | 0.00006 seconds |
15
+ ./spec/gaskit/contract_registry_spec.rb[1:2:1] | passed | 0.00042 seconds |
16
+ ./spec/gaskit/contract_registry_spec.rb[1:2:2] | passed | 0.00007 seconds |
17
+ ./spec/gaskit/contract_registry_spec.rb[1:2:3] | passed | 0.00006 seconds |
18
+ ./spec/gaskit/contract_registry_spec.rb[1:2:4] | passed | 0.00004 seconds |
19
+ ./spec/gaskit/contract_registry_spec.rb[1:3:1] | passed | 0.00004 seconds |
20
+ ./spec/gaskit/contract_registry_spec.rb[1:3:2] | passed | 0.00003 seconds |
21
+ ./spec/gaskit/contract_registry_spec.rb[1:4:1] | passed | 0.00004 seconds |
22
+ ./spec/gaskit/contract_registry_spec.rb[1:4:2] | passed | 0.00004 seconds |
23
+ ./spec/gaskit/contract_registry_spec.rb[1:5:1] | passed | 0.00005 seconds |
24
+ ./spec/gaskit/contract_registry_spec.rb[1:5:2] | passed | 0.00004 seconds |
25
+ ./spec/gaskit/core_spec.rb[1:1:1] | passed | 0.00003 seconds |
26
+ ./spec/gaskit/core_spec.rb[1:1:2] | passed | 0.00003 seconds |
27
+ ./spec/gaskit/core_spec.rb[1:2:1] | passed | 0.00089 seconds |
28
+ ./spec/gaskit/core_spec.rb[1:3:1] | passed | 0.00337 seconds |
29
+ ./spec/gaskit/core_spec.rb[1:4:1] | passed | 0.00008 seconds |
30
+ ./spec/gaskit/core_spec.rb[1:5:1] | passed | 0.00004 seconds |
31
+ ./spec/gaskit/core_spec.rb[1:5:2] | passed | 0.00003 seconds |
32
+ ./spec/gaskit/core_spec.rb[1:6:1] | passed | 0.00005 seconds |
33
+ ./spec/gaskit/flow_spec.rb[1:1:1] | passed | 0.00098 seconds |
34
+ ./spec/gaskit/flow_spec.rb[1:1:2] | passed | 0.0002 seconds |
35
+ ./spec/gaskit/flow_spec.rb[1:1:3] | passed | 0.00019 seconds |
36
+ ./spec/gaskit/flow_spec.rb[1:2:1] | passed | 0.00014 seconds |
37
+ ./spec/gaskit/flow_spec.rb[1:3:1] | passed | 0.00022 seconds |
38
+ ./spec/gaskit/logger_spec.rb[1:1:1] | passed | 0.00008 seconds |
39
+ ./spec/gaskit/logger_spec.rb[1:2:1] | passed | 0.00134 seconds |
40
+ ./spec/gaskit/logger_spec.rb[1:2:2] | passed | 0.00006 seconds |
41
+ ./spec/gaskit/logger_spec.rb[1:3:1] | passed | 0.00005 seconds |
42
+ ./spec/gaskit/logger_spec.rb[1:4:1] | passed | 0.00006 seconds |
43
+ ./spec/gaskit/logger_spec.rb[1:4:2] | passed | 0.00004 seconds |
44
+ ./spec/gaskit/logger_spec.rb[1:4:3] | passed | 0.00004 seconds |
45
+ ./spec/gaskit/operation_exit_spec.rb[1:1:1] | passed | 0.00003 seconds |
46
+ ./spec/gaskit/operation_exit_spec.rb[1:1:2] | passed | 0.00002 seconds |
47
+ ./spec/gaskit/operation_exit_spec.rb[1:2:1] | passed | 0.00002 seconds |
48
+ ./spec/gaskit/operation_exit_spec.rb[1:2:2] | passed | 0.00003 seconds |
49
+ ./spec/gaskit/operation_exit_spec.rb[1:3:1] | passed | 0.00002 seconds |
50
+ ./spec/gaskit/operation_result_spec.rb[1:1:1] | passed | 0.00004 seconds |
51
+ ./spec/gaskit/operation_result_spec.rb[1:1:2] | passed | 0.00003 seconds |
52
+ ./spec/gaskit/operation_result_spec.rb[1:2:1] | passed | 0.00003 seconds |
53
+ ./spec/gaskit/operation_result_spec.rb[1:2:2] | passed | 0.00003 seconds |
54
+ ./spec/gaskit/operation_result_spec.rb[1:2:3] | passed | 0.00003 seconds |
55
+ ./spec/gaskit/operation_result_spec.rb[1:3:1] | passed | 0.00003 seconds |
56
+ ./spec/gaskit/operation_result_spec.rb[1:4:1] | passed | 0.00003 seconds |
57
+ ./spec/gaskit/operation_result_spec.rb[1:4:2] | passed | 0.00003 seconds |
58
+ ./spec/gaskit/operation_result_spec.rb[1:4:3] | passed | 0.00003 seconds |
59
+ ./spec/gaskit/operation_spec.rb[1:1:1] | passed | 0.00005 seconds |
60
+ ./spec/gaskit/operation_spec.rb[1:1:2] | passed | 0.00014 seconds |
61
+ ./spec/gaskit/operation_spec.rb[1:1:3] | passed | 0.00006 seconds |
62
+ ./spec/gaskit/operation_spec.rb[1:1:4] | passed | 0.00006 seconds |
63
+ ./spec/gaskit/operation_spec.rb[1:2:1] | passed | 0.00007 seconds |
64
+ ./spec/gaskit/operation_spec.rb[1:3:1] | passed | 0.0001 seconds |
65
+ ./spec/gaskit/operation_spec.rb[1:4:1] | passed | 0.00015 seconds |
66
+ ./spec/gaskit/operation_spec.rb[1:5:1] | passed | 0.00005 seconds |
67
+ ./spec/gaskit/repository_spec.rb[1:1:1] | passed | 0.00006 seconds |
68
+ ./spec/gaskit/repository_spec.rb[1:2:1] | passed | 0.00014 seconds |
69
+ ./spec/gaskit/repository_spec.rb[1:2:2] | passed | 0.00009 seconds |
70
+ ./spec/gaskit/repository_spec.rb[1:3:1] | passed | 0.00006 seconds |
71
+ ./spec/gaskit/repository_spec.rb[1:3:2] | passed | 0.00013 seconds |
72
+ ./spec/gaskit/repository_spec.rb[1:4:1] | passed | 0.00018 seconds |
73
+ ./spec/gaskit/repository_spec.rb[1:4:2] | passed | 0.00014 seconds |
74
+ ./spec/gaskit_spec.rb[1:1] | passed | 0.00004 seconds |
75
+ ./spec/gaskit_spec.rb[1:2] | passed | 0.00013 seconds |
data/.rubocop.yml ADDED
@@ -0,0 +1,33 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7.0
3
+ NewCops: enable
4
+ SuggestExtensions: true
5
+
6
+ Style/Documentation:
7
+ Exclude:
8
+ - lib/gaskit/**/*.rb
9
+
10
+ Style/StringLiterals:
11
+ Enabled: true
12
+ EnforcedStyle: double_quotes
13
+
14
+ Style/StringLiteralsInInterpolation:
15
+ Enabled: true
16
+ EnforcedStyle: double_quotes
17
+
18
+ Gemspec/DevelopmentDependencies:
19
+ EnforcedStyle: gemspec
20
+
21
+ Layout/LineLength:
22
+ Max: 120
23
+
24
+ Metrics/ClassLength:
25
+ Max: 150
26
+
27
+ Metrics/BlockLength:
28
+ Exclude:
29
+ - gaskit.gemspec
30
+ - spec/**/*.rb
31
+
32
+ Metrics/MethodLength:
33
+ Max: 20
data/CHANGELOG.md ADDED
@@ -0,0 +1,110 @@
1
+ ## [0.1.4] - 2025-04-08
2
+
3
+ ### Added
4
+
5
+ - Error registration support in `Gaskit::Operation` via the `error` class method. This allows declaring symbolic exit keys with associated messages and optional codes.
6
+
7
+ ```ruby
8
+ class MyOperation < Gaskit::Operation
9
+ error :unauthorized, 'User must be authorized', code: 401
10
+
11
+ def call
12
+ exit(:unauthorized)
13
+ end
14
+ end
15
+ ```
16
+
17
+ - Structured `exit` and `error` payloads in `OperationResult#to_h`:
18
+ - `:exit` is present when an operation exited early (via `exit(:key)`), containing:
19
+ - `key`: the symbolic reason (e.g. `:unauthorized`)
20
+ - `message`: a friendly message
21
+ - `code`: optional numeric code if defined
22
+ - `:error` is present for handled errors, containing:
23
+ - `type`: class name of the error
24
+ - `message`: error message
25
+ - `backtrace`: full Ruby backtrace (if available)
26
+ - `:meta` contains duration and context
27
+
28
+ - `OperationResult#to_json` for automatic JSON serialization of the result object.
29
+
30
+ ### Changed
31
+
32
+ - `OperationResult#to_h` now returns:
33
+ - `success`: boolean
34
+ - `status`: one of `:success`, `:failure`, `:early_exit`
35
+ - `value`: only present on success
36
+ - `exit`: structured hash for early exits
37
+ - `error`: structured hash for raised errors
38
+ - `meta`: always includes `duration` and optionally includes `context`
39
+
40
+ ## [0.1.3] - 2025-04-08
41
+
42
+ ### Added
43
+ - `Gaskit::Repository` base class for service-layer data access patterns:
44
+ - Prevents instantiation (`.new` raises `TypeError`)
45
+ - Adds structured logging and execution time measurement via `.log_execution_time`
46
+ - Supports assigning a model with `.model(ModelClass)`
47
+ - Delegates common ActiveRecord-style methods (e.g., `find`, `where`, `create!`, etc.)
48
+ - Repository generator:
49
+ `rails generate gaskit:repository User`
50
+ Generates a file like `UserRepository` with `model User` already declared.
51
+
52
+ ### Changed
53
+ - `Repository.model` now enforces that a model can only be set once. Attempting to redefine the model raises a `RuntimeError`.
54
+ - `Repository.logger` returns a class-scoped `Gaskit::Logger` for structured log formatting with optional context.
55
+ - Refactored `.log_execution_time` to use `Gaskit::Helpers.time_execution` internally for cleaner timing logic.
56
+
57
+ ### Fixed
58
+ - Specs for `Gaskit::Repository` now use isolated, dynamically generated anonymous classes to avoid model assignment clashes across examples.
59
+ - Error messages in `.model` now include the class name for clarity (e.g., `UserRepository already has a model set`).
60
+
61
+ ### Specs
62
+ - Full test coverage
63
+
64
+ ## [0.1.2] - 2025-04-08
65
+
66
+ ### Changed
67
+ - General cleanup and test coverage.
68
+
69
+ ## [0.1.1] - 2025-04-08
70
+
71
+ ### Added
72
+ - `Gaskit::Flow` and `Gaskit::FlowResult` for composing multi-step operation pipelines with full step tracking, duration timing, and input/output logging.
73
+ - Support for inline and class-based `Flow` definitions using `step` DSL.
74
+ - `step_input` and `compile_step_entry` helpers to track arguments and keyword arguments passed to each flow step.
75
+ - `Gaskit::ContractRegistry` with result class validation, contract registration, and fetching.
76
+ - `Gaskit::Configuration` with customizable:
77
+ - `logger`, `log_level`, `log_formatter`, and `disable_logging`
78
+ - dynamic `context` provider (e.g., for request or user metadata)
79
+ - contract registration and access
80
+ - `Gaskit::OperationResult` class:
81
+ - Unified result structure for all operations
82
+ - Success/failure helpers, `#to_h` serialization, and human-readable `#inspect`
83
+ - `Gaskit::OperationExit` for early exits with symbolic keys and messages.
84
+
85
+ ### Changed
86
+ - `Operation.result_class` now falls back to the superclass's contract when not explicitly set.
87
+ - `Operation.invoke` raises a clear `NotImplementedError` if no contract is defined.
88
+ - `Operation.call` and `call!` now log duration in a readable format (`"0.000123"`).
89
+ - Refined flow step result propagation:
90
+ - Arrays are passed as positional args
91
+ - Hashes as keyword args
92
+ - Single values are normalized into `[value], {}`
93
+
94
+ ### Fixed
95
+ - Resolved double-registration issues in test contracts by using randomized contract names in specs.
96
+ - Ensured each step’s inputs and outputs are correctly logged and serialized in `FlowResult#steps`.
97
+
98
+ ### Specs
99
+ - Full test coverage added for:
100
+ - `Gaskit::Operation` (contract handling, success/failure, early exits)
101
+ - `Gaskit::ContractRegistry` (validation, fetch, override, registration errors)
102
+ - `Gaskit::Configuration` (logger settings, contract management)
103
+ - `Gaskit::OperationResult` and `OperationExit`
104
+ - `Gaskit::Flow` and `FlowResult`, including multi-step execution and error propagation
105
+
106
+ ---
107
+
108
+ ## [0.1.0] - 2025-04-06
109
+
110
+ - 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 bnlucas@outlook.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) 2025 Nathan Lucas
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,178 @@
1
+ # Gaskit
2
+
3
+ Gaskit is a flexible, pluggable, and structured operations framework for Ruby and Rails applications. It provides a consistent way to implement application logic using service objects, query objects, flows, and contracts — with robust support for early exits, structured logging, duration tracking, and failure handling.
4
+
5
+ ## ✨ Features
6
+
7
+ - ✅ `Operation`, `Service`, and `Query` classes
8
+ - 🔀 Customizable result and early exit contracts via `use_contract`
9
+ - 🧱 Composable multi-step flows using `Flow` DSL
10
+ - 🧪 Built-in error declarations and early exits via `exit(:key)`
11
+ - ⏱ Integrated duration tracking and structured logging
12
+ - 🧰 Generators for Rails to scaffold operations, services, queries, flows, and repositories
13
+
14
+ ## 📦 Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'gaskit'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ ```bash
25
+ $ bundle install
26
+ ```
27
+
28
+ Or install it yourself as:
29
+
30
+ ```bash
31
+ $ gem install gaskit
32
+ ```
33
+
34
+ ## 🔧 Configuration
35
+
36
+ You can configure Gaskit via an initializer:
37
+
38
+ ```ruby
39
+ Gaskit.configure do |config|
40
+ config.context_provider = -> { { request_id: RequestStore.store[:request_id] } }
41
+ config.setup_logger(Logger.new($stdout), formatter: Gaskit::Logger.formatter(:pretty))
42
+ end
43
+ ```
44
+
45
+ ## 🚀 Usage
46
+
47
+ ### Define an Operation
48
+
49
+ ```ruby
50
+ class MyOp < Gaskit::Operation
51
+ use_contract :service
52
+
53
+ def call(user_id:)
54
+ user = User.find_by(id: user_id)
55
+ exit(:not_found, "User not found") unless user
56
+
57
+ logger.info("Found user id=#{user_id}")
58
+ user
59
+ end
60
+ end
61
+ ```
62
+
63
+ ### Handle Result
64
+
65
+ ```ruby
66
+ result = MyOp.call(user_id: 42)
67
+
68
+ if result.success?
69
+ puts "Found user: #{result.value}"
70
+ elsif result.early_exit?
71
+ puts "Early exit: #{result.to_h[:exit]}"
72
+ else
73
+ puts "Failure: #{result.to_h[:error]}"
74
+ end
75
+ ```
76
+
77
+ ### Define Errors
78
+
79
+ ```ruby
80
+ class AuthOp < Gaskit::Operation
81
+ error :unauthorized, "Not allowed", code: "AUTH-001"
82
+
83
+ def call
84
+ exit(:unauthorized)
85
+ end
86
+ end
87
+ ```
88
+
89
+ ### Composing Flows
90
+
91
+ ```ruby
92
+ class CheckoutFlow < Gaskit::Flow
93
+ step AddToCart
94
+ step ApplyDiscount
95
+ step FinalizeOrder
96
+ end
97
+
98
+ result = CheckoutFlow.call(user_id: 123)
99
+ ```
100
+
101
+ ## 🧪 Generators
102
+
103
+ ```bash
104
+ # Generate an operation
105
+ rails generate gaskit:operation CreateUser
106
+
107
+ # Generate a query
108
+ rails generate gaskit:query FetchUsers
109
+
110
+ # Generate a service
111
+ rails generate gaskit:service RegisterAccount
112
+
113
+ # Generate a flow
114
+ rails generate gaskit:flow Checkout AddToCart ApplyDiscount FinalizeOrder
115
+
116
+ # Generate a repository
117
+ rails generate gaskit:repository User
118
+ ```
119
+
120
+ ## 📂 Contracts
121
+
122
+ You can define contracts using registered result types:
123
+
124
+ ```ruby
125
+ class MyResult < Gaskit::OperationResult; end
126
+
127
+ Gaskit.register_contract(:custom, MyResult)
128
+
129
+ class CustomOp < Gaskit::Operation
130
+ use_contract :custom
131
+ end
132
+ ```
133
+
134
+ Or override just part of the contract:
135
+
136
+ ```ruby
137
+ class CustomResult < Gaskit::OperationResult; end
138
+
139
+ class PartialContractOp < Gaskit::Operation
140
+ use_contract :service, result: CustomResult
141
+ end
142
+ ```
143
+
144
+ ## 🧱 Repositories
145
+
146
+ ```ruby
147
+ class UserRepository < Gaskit::Repository
148
+ model User
149
+
150
+ def find_by_name_or_slug(name, profile_slug)
151
+ where(name: name).or(where(profile_slug: profile_slug))
152
+ end
153
+ end
154
+
155
+ users = UserRepository.where(active: true)
156
+ user = UserRepository.find_by_name_or_slug("User", "user123")
157
+ ```
158
+
159
+ ## 📈 Logging
160
+
161
+ Gaskit includes a flexible logger with support for structured JSON or pretty logs:
162
+
163
+ ```ruby
164
+ logger = Gaskit::Logger.new(self.class)
165
+ logger.info("Started process", context: { user_id: 1 })
166
+ ```
167
+
168
+ ## 🤝 Contributing
169
+
170
+ Bug reports and pull requests are welcome! Feel free to fork, extend, and share improvements.
171
+
172
+ ## 📜 License
173
+
174
+ This gem is licensed under the [MIT License](LICENSE).
175
+
176
+ ---
177
+
178
+ Made with ❤️ by bnlucas
data/gasket-0.1.0.gem ADDED
Binary file
data/gaskit.gemspec ADDED
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/gaskit/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "gaskit"
7
+ spec.version = Gaskit::VERSION
8
+ spec.authors = ["Nathan Lucas"]
9
+ spec.email = ["bnlucas@outlook.com"]
10
+
11
+ spec.summary = "Composable operation pattern with structured results and logging."
12
+ spec.description = "Gaskit provides a lightweight, extensible framework for encapsulating business logic " \
13
+ "using a consistent, composable operation pattern. It supports context propagation, exit " \
14
+ "handling, structured results, and flexible logging via configuration."
15
+ spec.homepage = "https://github.com/bnlucas/gaskit"
16
+ spec.license = "MIT"
17
+ spec.required_ruby_version = ">= 2.7.0"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/bnlucas/gaskit"
21
+ spec.metadata["changelog_uri"] = "https://github.com/bnlucas/gaskit/blob/main/CHANGELOG.md"
22
+ spec.metadata["rubygems_mfa_required"] = "true"
23
+
24
+ # Only include files tracked by git, but exclude common dev/test files
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ f.start_with?(*%w[spec/ test/ features/ .git .github Gemfile Rakefile])
28
+ end
29
+ end
30
+
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ # Runtime dependencies (add if needed)
36
+ spec.add_dependency "railties", "~> 7.0"
37
+
38
+ # Development dependencies
39
+ spec.add_development_dependency "rspec", "~> 3.12"
40
+ spec.add_development_dependency "rubocop", "~> 1.60"
41
+ spec.add_development_dependency "yard", "~> 0.9"
42
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gaskit
4
+ # Represents a result object specific for query-related operations.
5
+ #
6
+ # @example Handling results from a query operation
7
+ # result = Gaskit::QueryResult.new(true, { records: [] }, nil, 2.45)
8
+ # if result.success?
9
+ # puts "Query succeeded with records: #{result.value[:records]}"
10
+ # else
11
+ # puts "Query failed: #{result.reason}"
12
+ # end
13
+ class QueryResult < OperationResult; end
14
+
15
+ Gaskit.register_contract(:query, QueryResult)
16
+
17
+ # A base class for query-style operations.
18
+ #
19
+ # This uses the `:query` contract, which must be registered with Gaskit::Registry.
20
+ #
21
+ # @example
22
+ # class FindUsers < Gaskit::Query
23
+ # def call
24
+ # User.active
25
+ # end
26
+ # end
27
+ class Query < Operation
28
+ use_contract :query
29
+ end
30
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gaskit
4
+ # Represents a result object specific for service-related operations.
5
+ #
6
+ # @example Handling results from a service operation
7
+ # result = Gaskit::ServiceResult.new(false, nil, RuntimeError.new("Service failed"), 0.89)
8
+ # if result.failure?
9
+ # puts "Service failed: #{result.reason}"
10
+ # end
11
+ class ServiceResult < OperationResult; end
12
+
13
+ Gaskit.register_contract(:service, ServiceResult)
14
+
15
+ # A base class for service-style operations.
16
+ #
17
+ # This uses the `:service` contract, which must be registered with Registry.
18
+ #
19
+ # @example
20
+ # class MyService < Service
21
+ # def call
22
+ # "done"
23
+ # end
24
+ # end
25
+ class Service < Operation
26
+ use_contract :service
27
+ end
28
+ end