{"id":29175774,"url":"https://github.com/r95-del/recycle_bin","last_synced_at":"2025-07-01T16:09:29.638Z","repository":{"id":295194571,"uuid":"989444244","full_name":"R95-del/recycle_bin","owner":"R95-del","description":"RecycleBin provides a \"trash can\" or \"recycle bin\" functionality where deleted records are marked as deleted instead of being permanently removed from your database. You can easily restore them or permanently delete them through a clean web interface.","archived":false,"fork":false,"pushed_at":"2025-05-27T14:28:18.000Z","size":269,"stargazers_count":3,"open_issues_count":5,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-28T15:06:37.656Z","etag":null,"topics":["bin","recycle","ruby","ruby-gem","ruby-on-rails","ruby-recycle-bin","ruby-trash","rubygem","rubygems","trash"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/recycle_bin","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/R95-del.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-24T05:32:21.000Z","updated_at":"2025-05-26T12:54:45.000Z","dependencies_parsed_at":"2025-05-24T06:32:02.663Z","dependency_job_id":"8ebc2b56-5797-41a5-b917-c18a299c55a8","html_url":"https://github.com/R95-del/recycle_bin","commit_stats":null,"previous_names":["r95-del/recycle_bin"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/R95-del/recycle_bin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R95-del%2Frecycle_bin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R95-del%2Frecycle_bin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R95-del%2Frecycle_bin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R95-del%2Frecycle_bin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/R95-del","download_url":"https://codeload.github.com/R95-del/recycle_bin/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R95-del%2Frecycle_bin/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262996475,"owners_count":23396905,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bin","recycle","ruby","ruby-gem","ruby-on-rails","ruby-recycle-bin","ruby-trash","rubygem","rubygems","trash"],"created_at":"2025-07-01T16:09:28.634Z","updated_at":"2025-07-01T16:09:29.628Z","avatar_url":"https://github.com/R95-del.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e🗑️ RecycleBin\u003c/h1\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/R95-del/recycle_bin/main/docs/logo.svg\" alt=\"RecycleBin Logo\" width=\"120\" height=\"120\"\u003e\n  \u003cp\u003e\u003cstrong\u003eElegant soft delete solution for Ruby on Rails applications\u003c/strong\u003e\u003c/p\u003e\n  \u003cp\u003e\n    \u003ca href=\"https://rubygems.org/gems/recycle_bin\"\u003e\n      \u003cimg src=\"https://img.shields.io/gem/v/recycle_bin?style=for-the-badge\u0026logo=rubygems\u0026logoColor=white\u0026color=667eea\" alt=\"Gem Version\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/R95-del/recycle_bin/actions\"\u003e\n      \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/R95-del/recycle_bin/main.yml?style=for-the-badge\u0026logo=github\u0026logoColor=white\u0026color=28a745\" alt=\"CI Status\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/R95-del/recycle_bin/discussions\"\u003e\n      \u003cimg src=\"https://img.shields.io/github/discussions/R95-del/recycle_bin?style=for-the-badge\u0026logo=github\u0026logoColor=white\u0026color=007bff\" alt=\"GitHub Discussions\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/R95-del/recycle_bin/blob/main/LICENSE.txt\"\u003e\n      \u003cimg src=\"https://img.shields.io/github/license/R95-del/recycle_bin?style=for-the-badge\u0026color=764ba2\" alt=\"MIT License\"\u003e\n    \u003c/a\u003e\n  \u003c/p\u003e\n  \u003cp\u003e\n    \u003ca href=\"https://recyclebin.vercel.app\"\u003e📖 Documentation\u003c/a\u003e •\n    \u003ca href=\"https://github.com/R95-del/recycle_bin/blob/main/CHANGELOG.md\"\u003e📋 Changelog\u003c/a\u003e •\n    \u003ca href=\"https://github.com/R95-del/recycle_bin/discussions\"\u003e💬 Discussions\u003c/a\u003e •\n    \u003ca href=\"https://rubygems.org/gems/recycle_bin\"\u003e💎 RubyGems\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\nA simple and elegant soft delete solution for Rails applications with a beautiful web interface to manage your deleted records.\n\n**RecycleBin** provides a \"trash can\" or \"recycle bin\" functionality where deleted records are marked as deleted instead of being permanently removed from your database. You can easily restore them or permanently delete them through a clean web interface.\n\n## Features ✨\n\n- **Soft Delete**: Records are marked as deleted instead of being permanently removed\n- **Web Interface**: Beautiful, responsive dashboard to view and manage deleted items\n- **Easy Integration**: Simple module inclusion in your models\n- **Bulk Operations**: Restore or permanently delete multiple items at once\n- **Model Filtering**: Filter deleted items by model type and time\n- **Rails Generators**: Automated setup with generators\n- **Configurable**: Flexible configuration options\n- **Statistics Dashboard**: Overview of your deleted items\n\n## Installation 📦\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'recycle_bin', '~\u003e 1.1'\n```\n\nAnd then execute:\n\n```bash\n$ bundle install\n```\n\nOr install it yourself as:\n\n```bash\n$ gem install recycle_bin\n```\n\n## Quick Setup 🚀\n\n### 1. Run the install generator\n\n```bash\n$ rails generate recycle_bin:install\n```\n\nThis will:\n- Create a configuration file at `config/initializers/recycle_bin.rb`\n- Add the mount point to your routes\n- Display setup instructions\n\n### 2. Add deleted_at column to your models\n\nFor each model you want to soft delete, run:\n\n```bash\n$ rails generate recycle_bin:add_deleted_at ModelName\n```\n\nFor example:\n```bash\n$ rails generate recycle_bin:add_deleted_at User\n$ rails generate recycle_bin:add_deleted_at Post\n$ rails generate recycle_bin:add_deleted_at Comment\n```\n\nThis generates a migration to add the `deleted_at` column and index.\n\n### 3. Run the migrations\n\n```bash\n$ rails db:migrate\n```\n\n### 4. Include the module in your models\n\nAdd `RecycleBin::SoftDeletable` to any model you want to soft delete:\n\n```ruby\nclass User \u003c ApplicationRecord\n  include RecycleBin::SoftDeletable\nend\n\nclass Post \u003c ApplicationRecord\n  include RecycleBin::SoftDeletable\nend\n\nclass Comment \u003c ApplicationRecord\n  include RecycleBin::SoftDeletable\nend\n```\n\n### 5. Visit the web interface\n\nNavigate to `/recycle_bin` in your Rails application to see the web interface!\n\n## Usage 💡\n\n### Basic Operations\n\nOnce you've included the `RecycleBin::SoftDeletable` module in your models:\n\n```ruby\n# Create a record\nuser = User.create(name: \"John Doe\", email: \"john@example.com\")\n\n# Soft delete (goes to trash)\nuser.destroy\n# or\nuser.soft_delete\n\n# Check if deleted\nuser.deleted? # =\u003e true\n\n# Restore from trash\nuser.restore\n\n# Permanently delete (careful!)\nuser.destroy!\n```\n\n### Querying Records\n\nThe module provides several useful scopes:\n\n```ruby\n# Get all active (non-deleted) records (default scope)\nUser.all\n\n# Get only deleted records\nUser.deleted\n\n# Get all records including deleted ones\nUser.with_deleted\n\n# Get only deleted records (alias)\nUser.only_deleted\n\n# Get non-deleted records explicitly\nUser.not_deleted\n\n# Restore a deleted record by ID\nUser.restore(123)\n```\n\n### Web Interface Features\n\nThe web interface (`/recycle_bin`) provides:\n\n- **Dashboard Overview**: Statistics about deleted items\n- **Item Listing**: View all deleted records with details\n- **Filtering**: Filter by model type (User, Post, Comment, etc.)\n- **Time Filters**: View items deleted today, this week, or this month\n- **Individual Actions**: Restore or permanently delete single items\n- **Bulk Actions**: Select multiple items to restore or delete\n- **Item Details**: Click on any item to see full details and history\n\n## Configuration ⚙️\n\nConfigure RecycleBin in `config/initializers/recycle_bin.rb`:\n\n```ruby\nRecycleBin.configure do |config|\n  # Enable/disable web interface (default: true)\n  config.enable_web_interface = true\n\n  # Items per page in web interface (default: 25)\n  config.items_per_page = 50\n\n  # Auto-cleanup items after specified time (default: nil - disabled)\n  config.auto_cleanup_after = 30.days\n\n  # Method to get current user for audit trail (default: :current_user)\n  config.current_user_method = :current_user\n\n  # Authorization callback - restrict access to admins only\n  config.authorize_with do |controller|\n    # Example: Only allow admins\n    controller.current_user\u0026.admin?\n  end\nend\n```\n\n### Authorization\n\nTo restrict access to the web interface, use the `authorize_with` configuration:\n\n```ruby\nRecycleBin.configure do |config|\n  config.authorize_with do |controller|\n    # Only allow admins\n    controller.current_user\u0026.admin?\n  end\nend\n```\n\nIf authorization fails, users will be redirected with an \"Access denied\" message.\n\n## Advanced Usage 🔧\n\n### Custom Title Display\n\nBy default, RecycleBin tries to use `title`, `name`, or `email` fields for display. You can customize this:\n\n```ruby\nclass User \u003c ApplicationRecord\n  include RecycleBin::SoftDeletable\n\n  def recyclable_title\n    \"#{first_name} #{last_name} (#{email})\"\n  end\nend\n```\n\n### Associations and Dependencies\n\nRecycleBin works with Rails associations. The web interface will show related items:\n\n```ruby\nclass User \u003c ApplicationRecord\n  include RecycleBin::SoftDeletable\n  has_many :posts, dependent: :destroy\nend\n\nclass Post \u003c ApplicationRecord\n  include RecycleBin::SoftDeletable\n  belongs_to :user\n  has_many :comments, dependent: :destroy\nend\n```\n\n### Statistics and Reporting\n\nGet statistics about your deleted items:\n\n```ruby\n# Get overall statistics\nRecycleBin.stats\n# =\u003e { deleted_items: 45, models_with_soft_delete: [\"User\", \"Post\", \"Comment\"] }\n\n# Count deleted items across all models\nRecycleBin.count_deleted_items # =\u003e 45\n\n# Get models that have soft delete enabled\nRecycleBin.models_with_soft_delete # =\u003e [\"User\", \"Post\", \"Comment\"]\n```\n\n## API Reference 📚\n\n### Instance Methods\n\n- `soft_delete` - Mark record as deleted\n- `restore` - Restore deleted record\n- `deleted?` - Check if record is deleted\n- `destroy` - Soft delete (overrides Rails default)\n- `destroy!` - Permanently delete from database\n- `recyclable_title` - Display title for web interface\n\n### Class Methods\n\n- `.deleted` - Scope for deleted records only\n- `.not_deleted` - Scope for active records only\n- `.with_deleted` - Scope for all records including deleted\n- `.only_deleted` - Alias for `.deleted`\n- `.restore(id)` - Restore a record by ID\n- `.deleted_records` - Get all deleted records\n\n### Configuration Options\n\n- `enable_web_interface` - Enable/disable web UI (default: true)\n- `items_per_page` - Pagination limit (default: 25)\n- `auto_cleanup_after` - Auto-delete after time period (default: nil)\n- `current_user_method` - Method to get current user (default: :current_user)\n- `authorize_with` - Authorization callback block\n\n## Generators 🛠️\n\n### Install Generator\n\n```bash\n$ rails generate recycle_bin:install\n```\n\nSets up RecycleBin in your Rails application.\n\n### Add DeletedAt Generator\n\n```bash\n$ rails generate recycle_bin:add_deleted_at ModelName\n```\n\nAdds the `deleted_at` column to the specified model.\n\n## Web Interface Routes 🛣️\n\nThe gem adds these routes to your application:\n\n```\nGET    /recycle_bin              # Dashboard/index\nGET    /recycle_bin/trash        # List all deleted items\nGET    /recycle_bin/trash/:model_type/:id # Show specific item\nPATCH  /recycle_bin/trash/:model_type/:id/restore # Restore item\nDELETE /recycle_bin/trash/:model_type/:id # Permanently delete\nPATCH  /recycle_bin/trash/bulk_restore    # Bulk restore\nDELETE /recycle_bin/trash/bulk_destroy    # Bulk delete\n```\n\n## Requirements 📋\n\n- **Ruby**: \u003e= 2.7.0\n- **Rails**: \u003e= 6.0\n- **Database**: Any database supported by Rails (PostgreSQL, MySQL, SQLite, etc.)\n\n## Examples 💼\n\n### E-commerce Store\n\n```ruby\nclass Product \u003c ApplicationRecord\n  include RecycleBin::SoftDeletable\n  \n  def recyclable_title\n    \"#{name} - #{sku}\"\n  end\nend\n\n# Soft delete a product\nproduct = Product.find(1)\nproduct.destroy # Goes to trash, can be restored\n\n# View deleted products in admin panel at /recycle_bin\n```\n\n### Blog System\n\n```ruby\nclass Post \u003c ApplicationRecord\n  include RecycleBin::SoftDeletable\n  belongs_to :author, class_name: 'User'\n  \n  def recyclable_title\n    title.truncate(50)\n  end\nend\n\nclass Comment \u003c ApplicationRecord\n  include RecycleBin::SoftDeletable\n  belongs_to :post\n  belongs_to :user\n  \n  def recyclable_title\n    \"Comment by #{user.name}: #{body.truncate(30)}\"\n  end\nend\n```\n\n### User Management\n\n```ruby\nclass User \u003c ApplicationRecord\n  include RecycleBin::SoftDeletable\n  \n  def recyclable_title\n    \"#{name} (#{email})\"\n  end\nend\n\n# Admin can restore accidentally deleted users\nUser.deleted.each do |user|\n  puts \"Deleted user: #{user.recyclable_title}\"\nend\n```\n\n## Troubleshooting 🔍\n\n### Common Issues\n\n**1. \"uninitialized constant RecycleBin\" error**\n- Make sure you've added the gem to your Gemfile and run `bundle install`\n- Restart your Rails server\n\n**2. Routes not working**\n- Ensure you've run `rails generate recycle_bin:install`\n- Check that `mount RecycleBin::Engine =\u003e '/recycle_bin'` is in your `config/routes.rb`\n\n**3. Records not appearing in trash**\n- Verify you've included `RecycleBin::SoftDeletable` in your model\n- Ensure the `deleted_at` column exists (run the migration)\n- Check that you're calling `.destroy` not `.delete`\n\n**4. Web interface shows \"Access denied\"**\n- Check your authorization configuration in the initializer\n- Ensure the current user meets your authorization requirements\n\n### Debugging\n\nEnable debug logging to see what's happening:\n\n```ruby\n# In development.rb or console\nRails.logger.level = :debug\n```\n\n## Contributing 🤝\n\nBug reports and pull requests are welcome on GitHub at https://github.com/R95-del/recycle_bin.\n\n## License 📄\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Changelog 📝\n\n## [1.1.1] - 2025-05-26\n\n### Fixed\n- Fixed critical bug in user authentication flow\n- Resolved memory leak in background job processing\n- Corrected deprecation warnings for Rails 7.1 compatibility\n- Fixed race condition in concurrent database writes\n\n### Changed\n- Improved error handling in API responses\n- Updated dependency versions for security patches\n- Enhanced logging for better debugging experience\n\n### Security\n- Patched potential XSS vulnerability in form helpers\n- Updated vulnerable dependencies to secure versions\n\n## [1.1.0] - 2025-05-25\n\n### Added\n- **Proper pagination**: Navigate through all deleted records with page controls\n- **Configurable page sizes**: Choose 25, 50, 100, or 250 items per page  \n- **Accurate item counting**: Shows real total counts instead of limited counts\n- **Enhanced statistics**: Added today/week deletion counts\n- **Better performance**: Optimized handling of large datasets\n- **Per-page controls**: User-selectable items per page options\n- **Memory optimization**: DeletedItemsCollection class for efficient data handling\n\n### Fixed\n- **Removed artificial limits**: No more 25/100 item display limits that prevented showing all records\n- **Pagination persistence**: Filters maintained across page navigation\n- **Memory usage**: Better handling of large datasets without loading all into memory\n- **Count accuracy**: Total counts now reflect actual database records\n- **Performance bottlenecks**: Eliminated inefficient loading of all records at once\n\n### Changed\n- **TrashController**: Complete rewrite with proper pagination logic\n- **Index view**: Enhanced UI with comprehensive pagination controls and statistics\n- **RecycleBin module**: Improved counting methods and performance optimizations\n- **Statistics calculation**: More efficient counting without loading full record sets\n\n### Performance\n- **Large dataset support**: Now efficiently handles 5000+ deleted records\n- **Lazy loading**: Only loads current page items, not all records\n- **Optimized queries**: Better database query patterns for counting and filtering\n- **Memory efficient**: Reduced memory footprint for large trash collections\n\n### Technical Details\n- Added `DeletedItemsCollection` class for efficient pagination\n- Implemented proper offset/limit handling\n- Enhanced filtering with maintained pagination state\n- Improved error handling for large datasets\n\n## [1.0.0] - 2025-05-24\n\n### Added\n- Initial release of RecycleBin gem\n- Soft delete functionality for ActiveRecord models\n- Web interface for managing trashed items\n- Restore functionality for deleted records\n- Bulk operations for multiple items\n- JSON API support for programmatic access\n\n### Contributors\n- Rishi Somani\n- Shobhit Jain\n- Raghav Agrawal\n\n---\n\n**Made with ❤️ for the Rails community**\n\n*Need help? Open an issue on [GitHub](https://github.com/R95-del/recycle_bin) or check out the web interface at `/recycle_bin` in your Rails app.*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr95-del%2Frecycle_bin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr95-del%2Frecycle_bin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr95-del%2Frecycle_bin/lists"}