-
Notifications
You must be signed in to change notification settings - Fork 3
Add example implementations of service extensions #312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or 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
- Removed the old `Usual::Extensions::Example1` and its associated spec to clean up unused extensions. - Added new reusable service extensions under the `ApplicationService::Extensions` namespace: - `ApiAction::DSL` - `Authorization::DSL` - `ExternalApiRequest::DSL` - `Idempotent::DSL` - `PostCondition::DSL` - `Publishable::DSL` - `Rollbackable::DSL` - `StatusActive::DSL` - `Transactional::DSL` - Reimplemented `Example1` under `Usual::Extensions` and `Wrong::Extensions` with these reusable extensions to improve code modularity and maintainability.
- Renamed output attribute from `result` to `total` or `value` across applicable services and corresponding specs for consistent terminology. - Updated specs to properly validate the renamed attributes in both success and failure scenarios. - Introduced additional checks for `meta` property in exceptions to enhance error details.
- Updated multiple specs to include `:aggregate_failures` for improved testing of multiple expectations within a single example. - Simplified DSL method definitions by leveraging Ruby's shorthand syntax for keyword arguments. - Adjusted `publish` and `post_condition!` methods for better readability and consistency. - Refactored example definitions in `Publishable`, `ExternalApiRequest`, and `Rollbackable` extensions.
- Introduced consistent input and output validation using the `have_input` and `have_output` matchers. - Added `:aggregate_failures` for enhanced testing of multiple expectations within a single example. - Reorganized success and failure scenarios with clear validations and outputs in extensions. - Improved readability by simplifying example definitions, standardizing output attributes, and aligning API requests with expected behavior.
- Deleted `it_behaves_like "failure result class"` from various specs, including `Idempotent`, `ApiAction`, `ExternalApiRequest`, `Transactional`, `PostCondition`, `Authorization`, `Rollbackable`, and `Publishable` extensions. - Retained focused examples with `:aggregate_failures` for clearer and more concise test cases. - Streamlined failure scenario definitions to improve readability and maintainability.
- Adjusted the order of `require_relative` statements in `Base` to ensure consistent and logical loading of extensions. - Moved `StatusActive::DSL` to align with other DSL modules for better readability and structure.
- Simplified DSL implementations by removing unnecessary private methods where applicable. - Renamed variables for clarity: replaced instance variables like `@_idempotency_was_cached` with local variables. - Improved error handling with explicit nil checks for configuration (e.g., idempotency store, transaction class, and event bus). - Consolidated logic in transactional, rollbackable, and external API request extensions for better readability. - Removed redundant calls to auxiliary methods in DSL extensions such as `_check_status_active`, `_perform_rollback`, and `_verify_post_conditions`.
- Added `README.md` to provide detailed guidelines for creating and using service extensions under `ApplicationService`. - Described common patterns (`Before`, `After`, `Around`, `On_failure`) and their use cases for extensibility. - Provided examples of configuration storage and execution wrapping (`call!`). - Highlighted best practices and recommendations for DSL design, error handling, and validations. - Listed available extensions with their respective patterns and purposes.
- Added detailed explanations for the `error_class` parameter in the `external_api_request` extension, emphasizing the importance of using specific exception classes and avoiding broad ones like `StandardError`. - Clarified the exception flow and logic for filtering and re-raising exceptions to preserve Servactory's behavior. - Documented the `rollbackable` extension's behavior, highlighting its handling of `StandardError` and maintaining the exception flow. - Updated the `README.md` to include these best practices and important notes for extension usage.
- Adjusted the `call!` method in `Idempotent::DSL` to disable additional RuboCop metrics (`Metrics/CyclomaticComplexity`, `Metrics/PerceivedComplexity`) for enhanced flexibility. - Retained existing overrides for `Metrics/AbcSize` and `Metrics/MethodLength` to preserve functionality.
- Introduced `Example2` under `Usual::Extensions::Rollbackable`, implementing a rollback mechanism with a new `LikeARollbackTracker` class for tracking rollback calls. - Added corresponding specs to validate input, output, and rollback behavior for `Example2`. - Enhanced rollback logic in the `Rollbackable::DSL` to exclude `success!` exceptions from triggering the rollback flow. - Adjusted `Authorization::DSL` and `StatusActive::DSL` to encapsulate conditional checks and improve maintainability. - Updated examples and documentation to reflect changes in execution and error-handling patterns, emphasizing pre-execution and post-execution behaviors.
…hecks - Updated `authorization` and `status_active` DSLs to use the `Before` pattern for pre-execution validation, ensuring side effects do not occur when checks fail. - Refactored `user_authorized?` methods to accept `incoming_arguments` for flexibility during pre-checks. - Adjusted specs to validate new pre-execution behavior for `authorization` and ensure service actions are not executed when unauthorized. - Simplified validations by removing redundant input checks. - Updated documentation to reflect pattern changes and highlight the proper use of pre-execution validation.
- Updated `call!` methods in `Authorization::DSL` and `StatusActive::DSL` to disable RuboCop's `Metrics/MethodLength` check. - No functional changes were introduced, maintaining existing behaviors. - Ensured code adheres to current complexity rules while improving maintainability.
- Deleted the `StatusActive::DSL` module as it is no longer needed. - Cleaned up related code to improve maintainability and reduce complexity. - Ensured no functional dependencies were affected by the removal.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.