-
-
Notifications
You must be signed in to change notification settings - Fork 829
Open
Milestone
Description
Let's reoganise the Ransack codebase so it is easier to follow. First complete this refactoring #1625
Proposed Ransack File Organization
1. Core Search Engine (lib/ransack/core/)
Purpose: Main search functionality and orchestration
core/
├── search.rb # Main Search class
├── context.rb # Search context management
├── visitor.rb # Arel visitor for query building
└── configuration.rb # Global configuration
2. Query Building (lib/ransack/query/)
Purpose: Query construction and node hierarchy
query/
├── nodes/
│ ├── node.rb # Base node class
│ ├── attribute.rb # Attribute nodes
│ ├── value.rb # Value nodes
│ ├── condition.rb # Condition nodes
│ ├── grouping.rb # Grouping nodes (AND/OR)
│ ├── sort.rb # Sort nodes
│ └── bindable.rb # Bindable interface
├── predicate.rb # Predicate definitions (eq, cont, etc.)
├── ransacker.rb # Custom ransacker definitions
└── naming.rb # Naming conventions
3. ActiveRecord Integration (lib/ransack/active_record/)
Purpose: ActiveRecord-specific functionality
active_record/
├── base.rb # ActiveRecord::Base extensions
├── context.rb # ActiveRecord-specific context
├── join_association.rb # Join association handling
├── join_association_7_2.rb # 7.2 compatibility
├── join_dependency.rb # Join dependency management
└── reflection.rb # Reflection extensions
4. User Interface (lib/ransack/helpers/)
Purpose: View helpers and form building
helpers/
├── form_builder.rb # Form builder helpers
├── form_helper.rb # Form helper methods
└── helpers.rb # Main helpers module
5. Internationalization (lib/ransack/i18n/)
Purpose: Translation and localization
i18n/
├── translate.rb # Translation logic
└── locale/ # Translation files
├── en.yml
├── fr.yml
└── ... (other locales)
6. Utilities (lib/ransack/utils/)
Purpose: Shared utilities and constants
utils/
├── constants.rb # Application constants
├── invalid_search_error.rb # Custom error classes
└── version.rb # Version information
7. Main Entry Point
lib/ransack.rb # Main entry point, requires all modules
Benefits
1. Clear Separation of Concerns
- Core: Search logic and orchestration
- Query: Query building and node hierarchy
- ActiveRecord: Database-specific functionality
- Helpers: UI and form building
- I18n: Internationalization
- Utils: Shared utilities
2. Logical Grouping
- Related functionality is grouped together
- Easy to find specific features
- Clear dependencies between modules
3. Scalability
- Easy to add new query types in
query/ - Easy to add new database adapters in
active_record/ - Easy to add new helpers in
helpers/
4. Maintainability
- Each namespace has a single responsibility
- Changes to one area don't affect others
- Clear boundaries for testing
Example of Updated File Structure
lib/ransack/
├── ransack.rb # Main entry point
├── core/
│ ├── search.rb
│ ├── context.rb
│ ├── visitor.rb
│ └── configuration.rb
├── query/
│ ├── nodes/
│ │ ├── node.rb
│ │ ├── attribute.rb
│ │ ├── value.rb
│ │ ├── condition.rb
│ │ ├── grouping.rb
│ │ ├── sort.rb
│ │ └── bindable.rb
│ ├── predicate.rb
│ ├── ransacker.rb
│ └── naming.rb
├── active_record/
│ ├── base.rb
│ ├── context.rb
│ ├── join_association.rb
│ ├── join_association_7_2.rb
│ ├── join_dependency.rb
│ └── reflection.rb
├── helpers/
│ ├── form_builder.rb
│ ├── form_helper.rb
│ └── helpers.rb
├── i18n/
│ ├── translate.rb
│ └── locale/
│ ├── en.yml
│ └── ...
└── utils/
├── constants.rb
├── invalid_search_error.rb
└── version.rb
Metadata
Metadata
Assignees
Labels
No labels