Skip to content

Add inventory system and enhance Treaty architecture#26

Merged
afuno merged 21 commits intomainfrom
feature/controller_data
Nov 22, 2025
Merged

Add inventory system and enhance Treaty architecture#26
afuno merged 21 commits intomainfrom
feature/controller_data

Conversation

@afuno
Copy link
Member

@afuno afuno commented Nov 20, 2025

No description provided.

- Introduced `Treaty::Inventory::Collection` to abstract inventory container logic.
- Added `Treaty::Inventory::Factory` to facilitate dynamic inventory creation and delegation.
- Updated controller DSL to support inventory injection via blocks.
- Refined specs to incorporate inventory instances in test scenarios.
- Introduced the `Inventory` system to pass controller-specific data to services.
- Added `Treaty::Inventory::Collection` for managing inventory items as a collection.
- Implemented `Treaty::Inventory::Factory` to define inventory through a DSL.
- Enabled inventory evaluation with a controller context for dynamic data injection.
- Enhanced Treaty execution to support inventory in Proc, Service, and Class executors.
- Documented the Inventory system and updated examples in README.
- Updated all instances of `controller_context` to `context` for simplification and consistency across the codebase.
- Modified method signatures and internal references in `Inventory`, `Collection`, and `Execution`.
- Ensured all inventory evaluation and execution logic reflect the new naming convention.
- Updated documentation to reflect the terminology change.
- Improved safety by adding nil checks to inventory collection evaluations.
- Replaced `block` checks with `block_given?` for clarity and correctness in `dsl.rb`.
- Updated comment examples in `posts_controller.rb` for better guidance and readability.
- Reduced `Forwardable` delegations in `Collection` to only essential methods (`<<` and `empty?`).
- Removed unused methods and redundant comments from `Collection` for leaner code and easier maintainability.
- Standardized parameter order across all `call!` and `_call!` methods for uniformity and readability.
- Adjusted method signatures in `Workspace` and `Callable` to prioritize `context` over `inventory`.
- Updated method calls and delegation chains to reflect the new parameter order.
- Improved maintainability by aligning method definitions with consistent patterns.
@afuno afuno added this to the v1.0.0 milestone Nov 20, 2025
@afuno afuno self-assigned this Nov 20, 2025
@afuno afuno added the feature label Nov 20, 2025
- Simplified inventory block handling by introducing `treaty_build_inventory_for` method.
- Allowed shorthand syntax for `provide` definitions when `from:` is omitted, improving readability.
- Updated documentation to clarify shorthand usage and expand examples for better guidance.
- Improved error messages to accommodate shorthand syntax in treaty blocks.
- Optimized `Collection` and `Factory` code by reducing redundancy and improving default handling in inventory sources.
- Updated documentation to mandate declaring `inventory` as an input in Servactory services.
- Simplified logic for passing `inventory` to services, removing unnecessary checks.
- Added the `#evaluate` method to `Inventory::Collection` for resolving inventory values dynamically.
- Modified existing services to include `inventory` as an optional input for consistency.
- Improved error handling when services receive undeclared inventory inputs.
- Added `Treaty::Executor::Inventory` class to provide intuitive, method-based access to inventory items.
- Updated inventory evaluation logic to return an `Inventory` instance with dynamic method support.
- Enhanced error handling to raise `Treaty::Exceptions::Inventory` for missing items or evaluation issues.
- Documented method-based access in services, highlighting its advantages over hash-based access.
- Updated affected services and specs to utilize `Treaty::Executor::Inventory` as the inventory input.
- Improved localization files with new error messages for inventory-related exceptions.
- Updated `Treaty::Executor::Inventory` to support lazy evaluation and caching of inventory items for optimized performance.
- Improved `evaluated_inventory` logic to create an inventory wrapper directly, replacing redundant data evaluations.
- Added architecture details to documentation, explaining lazy evaluation benefits and caching mechanisms.
- Refined method-based access to evaluate inventory items only on first access, storing results in cache for reuse.
- Enhanced error handling to provide better diagnostic messages for missing inventory items.
- Updated tests and examples to reflect lazy evaluation and caching improvements.
- Updated all spec files to replace `Inventory::Collection` initialization with `Executor::Inventory` for improved context awareness.
- Introduced `context` mock in specs to simulate controller dependencies.
- Enhanced inventory initialization logic to ensure compatibility with `exists?` method, aligning with recent inventory system improvements.
- Maintained test integrity by adapting shared examples to the new inventory structure.
- Replaced `double("controller")` with `instance_double(ApplicationController)` across all spec files to improve type safety.
- Updated relevant mock definitions for better alignment with `ApplicationController` dependencies.
- Improved test consistency with enhanced accuracy in simulating controller context.
- Removed the `strategy Treaty::Strategy::ADAPTER` key from `IndexTreaty` configuration as it was unused and redundant.
- Simplified the treaty definition for improved readability and maintainability.
- Updated the documentation accordingly.
@afuno afuno marked this pull request as ready for review November 20, 2025 20:12
# @param options [Hash] Optional :from key with source (defaults to inventory name)
# @return [Collection] The collection being built
# @raise [Treaty::Exceptions::Inventory] For invalid method or missing parameters
def method_missing(method_name, *args, **options, &_block) # rubocop:disable Metrics/MethodLength

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Производительность method_missing падает с ростом древа наследования в "родительском" классе. Сейчас наверно ок, но в дальнейшем надо будет рефачить

- Standardized variable naming in specs by replacing `inv` with `inventory` for improved clarity and consistency across tests.
- Extracted repeated execution parameter logic into a `build_call_params` method to eliminate duplication and simplify code.
- Optimized `respond_to_missing?` and `inspect` methods in `Executor::Inventory` by utilizing the new `names` method for better readability and reduced redundancy.
- Enhanced `find_inventory_item` method by introducing `find` for cleaner and efficient item lookups.
- Added `names` method to `Inventory::Collection` to provide a concise way to retrieve inventory item names.
- Improved documentation and comments for better understanding of changes and rationale.
- Introduced new examples demonstrating the use of the Inventory system for passing controller-specific data to services.
- Enhanced documentation with detailed sections on Treaty definitions, controllers, services, and service interactions.
- Added sections on inventory sources (symbol, lambda, direct value) for better clarity.
- Updated troubleshooting and cheatsheets with common inventory-related issues and resolutions.
- Refined request lifecycle documentation to include inventory preparation.
- Improved i18n localization with additional error messages related to inventory evaluation failures.
- Replaced `provide :current_user, from: :current_user` with the shorthand syntax `provide :current_user` in all documentation for consistency and readability.
- Updated examples, cheatsheets, reference materials, and troubleshooting guides to reflect the change.
- Simplified explanations surrounding `provide` shorthand usage, focusing on cases where the method source matches the name.
@afuno afuno added the claude label Nov 21, 2025
@claude

This comment was marked as outdated.

- Updated `code-review.yml` to include comprehensive sections for Inventory system, covering controller DSL, service integration, and error handling.
- Added Inventory system as a primary concept in `CLAUDE.md`, emphasizing its use for passing controller-specific data with lazy evaluation.
- Enhanced documentation with controller DSL examples, inventory evaluation patterns, and service integration workflows.
- Refactored sections to accommodate the new Inventory system, ensuring logical grouping and improved readability.
- Revised testing and error scenarios for inventory handling, supporting better diagnostics for missing or undefined items.
- Updated the `respond_to_missing?` method in `Treaty::Executor::Inventory` to return `false` instead of `true` when inventory is `nil`, ensuring proper behavior.
- Resolved potential errors caused by treating a `nil` inventory as having valid methods.
- Improved alignment with inventory evaluation logic for better reliability.
@afuno afuno removed the claude label Nov 21, 2025
- Updated the `call` method in `Posts::IndexService` across all documentation examples to switch parameter order from `(params:, inventory:)` to `(inventory:, params:)`.
- Ensured consistent parameter order for better alignment with common service conventions and improved readability.
- Revised examples, cheatsheets, troubleshooting, and defining-contracts sections to reflect this change.
@afuno afuno merged commit 426017a into main Nov 22, 2025
23 checks passed
@afuno afuno deleted the feature/controller_data branch November 22, 2025 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants