-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor hardcoded Post model to support acts_as_bunko_post on custom models #44
Copy link
Copy link
Open
Labels
refactorStuff we should improveStuff we should improve
Description
Description
The Collection concern has a post_model method that's hardcoded to return Post, which blocks the ability to use acts_as_bunko_post on models with different names (see #40). This creates a false abstraction and prevents the flexibility the concern pattern is designed to provide.
Current code
lib/bunko/controllers/collection.rb:112-114:
def post_model
@post_model ||= Post
endProblems this causes
- Blocks testing/using
acts_as_bunko_poston models other thanPost(Confirm acts_as_post and acts_as_post_type behavior on other models #40) - Creates false expectation of configurability (method exists but always returns same value)
- Users can't use a different model name if they already have a
Postmodel - Violates the concern pattern's goal of being reusable across models
Pros of refactoring
- Enables
acts_as_bunko_postto work on any model name - Unlocks Confirm acts_as_post and acts_as_post_type behavior on other models #40 functionality
- More flexible for edge cases (existing Post model, STI, namespaced models)
- Makes the abstraction actually useful
- Aligns with Rails concern best practices
Cons of refactoring
- Adds complexity to the bunko_collection macro
- Need to decide on default behavior (Post vs require explicit configuration)
- May require documentation updates
- Need to handle model name validation/existence
Recommended approach
Make the model configurable via the bunko_collection macro with a sensible default:
# In controller
bunko_collection :blog, model: "Article" # Optional, defaults to "Post"
# In Collection concern
class_attribute :bunko_post_model_name, default: "Post"
def bunko_collection(collection_name, model: "Post", **options)
self.bunko_post_model_name = model
# ... rest of setup
end
def post_model
@post_model ||= bunko_post_model_name.constantize
endThis maintains backward compatibility (defaults to Post) while enabling custom models.
Related issues
- Confirm acts_as_post and acts_as_post_type behavior on other models #40 - Testing acts_as macros on other models (this is a blocker for that)
References
lib/bunko/controllers/collection.rb:112-114
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
refactorStuff we should improveStuff we should improve