soft_trash 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f6ee0d17dc170db851c1e54e3083b63f7012df58230709a795c1590b5703f825
4
+ data.tar.gz: 47bfe90ed2d667f1374ad538e3fd88001723f43bfe90087cd9d6c6784f3e42d8
5
+ SHA512:
6
+ metadata.gz: ea9ab723ce25e9b5642d18b16b26d996b7a2d227f617e2c5e65739748b7da4e268314ed42234b99179d691b125a358cb2e34b2799c0c5206ba001466c05c53f7
7
+ data.tar.gz: 78ce637a5ebe311561a90a478f3315bb62d8f193e547e2c6949e68b840d41c235a0aadd7a7b099075838631fe638435fbadf280e57b2fdce0323b70c39deb2bc
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
data/.idea/misc.xml ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-3.1.1 [global]" project-jdk-type="RUBY_SDK" />
4
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/soft_trash.iml" filepath="$PROJECT_DIR$/.idea/soft_trash.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,75 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
+ </content>
12
+ <orderEntry type="inheritedJdk" />
13
+ <orderEntry type="sourceFolder" forTests="false" />
14
+ <orderEntry type="library" scope="PROVIDED" name="actionpack (v7.2.2.1, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="actionview (v7.2.2.1, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="activesupport (v7.2.2.1, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="base64 (v0.2.0, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="benchmark (v0.4.0, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="bigdecimal (v3.1.9, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="builder (v3.3.0, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.6.2, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.3.5, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="connection_pool (v2.5.0, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="crass (v1.0.6, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="date (v3.4.1, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.5.1, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
28
+ <orderEntry type="library" scope="PROVIDED" name="drb (v2.2.1, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="erubi (v1.13.1, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
30
+ <orderEntry type="library" scope="PROVIDED" name="i18n (v1.14.7, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="io-console (v0.8.0, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
32
+ <orderEntry type="library" scope="PROVIDED" name="irb (v1.15.1, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
33
+ <orderEntry type="library" scope="PROVIDED" name="json (v2.9.1, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
34
+ <orderEntry type="library" scope="PROVIDED" name="language_server-protocol (v3.17.0.3, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
35
+ <orderEntry type="library" scope="PROVIDED" name="logger (v1.6.5, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
36
+ <orderEntry type="library" scope="PROVIDED" name="loofah (v2.24.0, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
37
+ <orderEntry type="library" scope="PROVIDED" name="minitest (v5.25.4, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
38
+ <orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.18.2, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
39
+ <orderEntry type="library" scope="PROVIDED" name="parallel (v1.27.0, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
40
+ <orderEntry type="library" scope="PROVIDED" name="parser (v3.3.7.0, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
41
+ <orderEntry type="library" scope="PROVIDED" name="pp (v0.6.2, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
42
+ <orderEntry type="library" scope="PROVIDED" name="prettyprint (v0.2.0, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
43
+ <orderEntry type="library" scope="PROVIDED" name="psych (v5.2.3, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
44
+ <orderEntry type="library" scope="PROVIDED" name="racc (v1.8.1, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
45
+ <orderEntry type="library" scope="PROVIDED" name="rack (v3.1.8, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
46
+ <orderEntry type="library" scope="PROVIDED" name="rack-session (v2.1.0, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
47
+ <orderEntry type="library" scope="PROVIDED" name="rack-test (v2.2.0, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
48
+ <orderEntry type="library" scope="PROVIDED" name="rackup (v2.2.1, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
49
+ <orderEntry type="library" scope="PROVIDED" name="rails-dom-testing (v2.2.0, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
50
+ <orderEntry type="library" scope="PROVIDED" name="rails-html-sanitizer (v1.6.2, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
51
+ <orderEntry type="library" scope="PROVIDED" name="railties (v7.2.2.1, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
52
+ <orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
53
+ <orderEntry type="library" scope="PROVIDED" name="rake (v13.2.1, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
54
+ <orderEntry type="library" scope="PROVIDED" name="rdoc (v6.11.0, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
55
+ <orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.10.0, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
56
+ <orderEntry type="library" scope="PROVIDED" name="reline (v0.6.0, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
57
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.13.1, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
58
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.13.3, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
59
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.13.2, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
60
+ <orderEntry type="library" scope="PROVIDED" name="rspec-rails (v7.0.1, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
61
+ <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.13.1, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
62
+ <orderEntry type="library" scope="PROVIDED" name="rubocop (v1.71.0, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
63
+ <orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.37.0, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
64
+ <orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.13.0, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
65
+ <orderEntry type="library" scope="PROVIDED" name="securerandom (v0.4.1, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
66
+ <orderEntry type="library" scope="PROVIDED" name="sqlite3 (v1.7.3, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
67
+ <orderEntry type="library" scope="PROVIDED" name="stringio (v3.1.2, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
68
+ <orderEntry type="library" scope="PROVIDED" name="thor (v1.3.2, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
69
+ <orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.6, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
70
+ <orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v3.1.4, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
71
+ <orderEntry type="library" scope="PROVIDED" name="unicode-emoji (v4.0.4, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
72
+ <orderEntry type="library" scope="PROVIDED" name="useragent (v0.16.11, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
73
+ <orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.6.18, RVM: ruby-3.1.1 [global]) [gem]" level="application" />
74
+ </component>
75
+ </module>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
6
+ </component>
7
+ </project>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-08-22
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 mahendraxceed
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 mahendra.dabhi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # SoftTrash
2
+
3
+
4
+ Soft deletes for ActiveRecord done right. SoftTrash provides a simple and effective way to implement soft deletion in your Rails applications.
5
+
6
+ ## Features
7
+
8
+ - Simple integration with ActiveRecord models
9
+ - Customizable column names for soft delete functionality
10
+ - Scopes for including/excluding soft-deleted records
11
+ - Callbacks for soft deletion events
12
+ - Works with associations
13
+ - Supports Rails 5.2+ and Ruby 2.6+
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'soft_trash'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ ```bash
26
+ $ bundle install
27
+ ```
28
+
29
+ Or install it yourself as:
30
+
31
+ ```bash
32
+ $ gem install soft_trash
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ ### Basic Setup
38
+
39
+ 1. Generate and run the migration for a model:
40
+
41
+ ```bash
42
+ rails generate soft_trash:install Post
43
+ rails db:migrate
44
+ ```
45
+
46
+ ```ruby
47
+ add t.soft_trash
48
+ example
49
+
50
+ class CreatePosts < ActiveRecord::Migration[8.0]
51
+ def change
52
+ create_table :posts do |t|
53
+ t.string :name
54
+ t.soft_trash
55
+ t.timestamps
56
+ end
57
+ end
58
+ end
59
+
60
+ ```
61
+
62
+ 2. Include the module in your model:
63
+
64
+ ```ruby
65
+ class Post < ApplicationRecord
66
+ include SoftTrash::Model
67
+ end
68
+ ```
69
+
70
+ ### Default Behavior
71
+
72
+ By default, SoftTrash will:
73
+ - Add a `deleted_at` datetime column to track deletion
74
+ - Add a default scope to exclude soft-deleted records
75
+ - Override `destroy` to perform soft deletion
76
+ - Provide `really_destroy!` for permanent deletion
77
+
78
+ ### Scopes
79
+
80
+ ```ruby
81
+ # Get all records (default scope)
82
+ Post.all
83
+
84
+ # Get only non-deleted records
85
+ Post.active
86
+
87
+ # Get only deleted records
88
+ Post.deleted
89
+
90
+ ```
91
+
92
+ ### Instance Methods
93
+
94
+ ```ruby
95
+ post = Post.find(1)
96
+
97
+ # Soft delete a record
98
+ post.trash! # Sets deleted_at to current time
99
+
100
+ # Check if a record is soft-deleted
101
+ post.trashed? # => true
102
+
103
+ # Restore a soft-deleted record
104
+ post.restore!
105
+
106
+ # Check if a record is not soft-deleted
107
+ post.active? # => true
108
+
109
+ ```
110
+
111
+
112
+
113
+
114
+ ## Development
115
+
116
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
117
+
118
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
119
+
120
+ ## Contributing
121
+
122
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mahendraxceed/soft_trash. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/yourusername/soft_trash/blob/main/CODE_OF_CONDUCT.md).
123
+
124
+ ## License
125
+
126
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
127
+
128
+ ## Code of Conduct
129
+
130
+ Everyone interacting in the SoftTrash project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yourusername/soft_trash/blob/main/CODE_OF_CONDUCT.md).
131
+
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,54 @@
1
+ module SoftTrash
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+
6
+ source_root File.expand_path('templates', __dir__)
7
+
8
+ argument :model_name, type: :string, required: true, desc: "The table to add deleted_at to"
9
+
10
+ def self.next_migration_number(dirname)
11
+ next_migration_number = current_migration_number(dirname) + 1
12
+ [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.3d" % next_migration_number].max
13
+ end
14
+
15
+
16
+ def create_migration_file
17
+ migration_template(
18
+ 'add_deleted_at_to_tables.rb.erb',
19
+ "db/migrate/add_deleted_at_to_#{table_name}.rb",
20
+ migration_version: migration_version,
21
+ table_name: table_name
22
+ )
23
+ end
24
+
25
+ def inject_soft_trash_module
26
+ model_path = "app/models/#{model_name.singularize}.rb"
27
+
28
+ if File.exist?(model_path)
29
+ inject_into_file model_path, after: "ApplicationRecord\n" do
30
+ " include SoftTrash::Model\n"
31
+ end
32
+ else
33
+ create_file model_path do
34
+ "class #{model_name.classify} < ApplicationRecord\n" +
35
+ " include SoftTrash::Model\n" +
36
+ "end\n"
37
+ end
38
+ end
39
+ end
40
+
41
+
42
+ private
43
+
44
+ def table_name
45
+ model_name.underscore.pluralize
46
+ end
47
+
48
+
49
+ def migration_version
50
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,6 @@
1
+ class AddDeletedAtTo<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
2
+ def change
3
+ add_column :<%= table_name %>, :deleted_at, :datetime, default: nil
4
+ add_index :<%= table_name %>, :deleted_at
5
+ end
6
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SoftTrash
4
+
5
+ #
6
+ # Generic exception class.
7
+ class SoftTrashError < StandardError
8
+ end
9
+
10
+
11
+ class RecordNotTrasheded < SoftTrashError
12
+ attr_reader :record
13
+
14
+ def initialize(message = nil, record = nil)
15
+ @record = record
16
+ super(message)
17
+ end
18
+ end
19
+
20
+
21
+ class RecordNotRecovered < SoftTrashError
22
+ attr_reader :record
23
+
24
+ def initialize(message = nil, record = nil)
25
+ @record = record
26
+ super(message)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SoftTrash
4
+ # Handles soft deletes of records.
5
+ #
6
+ # Options:
7
+ #
8
+ # - :soft_trash_column - The columns used to track soft delete, defaults to `:deleted_at`.
9
+ module Model
10
+ extend ActiveSupport::Concern
11
+
12
+ included do
13
+ class_attribute :soft_trash_column
14
+ self.soft_trash_column = :deleted_at
15
+
16
+ scope :active, ->{ where(soft_trash_column => nil) }
17
+ scope :deleted, ->{ where.not(soft_trash_column => nil) }
18
+
19
+ define_model_callbacks :trash
20
+ define_model_callbacks :restore
21
+ end
22
+
23
+ # :nodoc:
24
+ module ClassMethods
25
+
26
+ # Person.where(age: 0..18).trash_all
27
+ def trash_all
28
+ active.each(&:trash)
29
+ end
30
+
31
+
32
+ #
33
+ # Person.where(age: 0..18).trash_all!
34
+ def trash_all!
35
+ active.each(&:trash!)
36
+ end
37
+
38
+
39
+ #
40
+ # Person.where(age: 0..18).undiscard_all
41
+ def restore_all
42
+ deleted.each(&:restore)
43
+ end
44
+
45
+ # Undiscards the records by instantiating each
46
+ # record and calling its {#undiscard!} method.
47
+ # Each object's callbacks are executed.
48
+ # Returns the collection of objects that were undiscarded.
49
+ #
50
+ # Note: Instantiation, callback execution, and update of each
51
+ # record can be time consuming when you're undiscarding many records at
52
+ # once. It generates at least one SQL +UPDATE+ query per record (or
53
+ # possibly more, to enforce your callbacks). If you want to undiscard many
54
+ # rows quickly, without concern for their associations or callbacks, use
55
+ # #update_all!(discarded_at: nil) instead.
56
+ #
57
+ # ==== Examples
58
+ #
59
+ # Person.where(age: 0..18).undiscard_all!
60
+ def restore_all!
61
+ deleted.each(&:restore!)
62
+ end
63
+ end
64
+
65
+ # @return [Boolean] true if this record has been discarded, otherwise false
66
+ def trashed?
67
+ self[self.class.soft_trash_column].present?
68
+ end
69
+
70
+ # @return [Boolean] false if this record has been discarded, otherwise true
71
+ def active?
72
+ !trashed?
73
+ end
74
+
75
+ # Discard the record in the database
76
+ #
77
+ # @return [Boolean] true if successful, otherwise false
78
+ def trash
79
+ return false if trashed?
80
+ run_callbacks(:trash) do
81
+ update_attribute(self.class.soft_trash_column, Time.current)
82
+ end
83
+ end
84
+
85
+ # Discard the record in the database
86
+ #
87
+ # There's a series of callbacks associated with #discard!. If the
88
+ # <tt>before_discard</tt> callback throws +:abort+ the action is cancelled
89
+ # and #discard! raises {Discard::RecordNotDiscarded}.
90
+ #
91
+ # @return [Boolean] true if successful
92
+ # @raise {Discard::RecordNotDiscarded}
93
+ def trash!
94
+ trash || _raise_record_not_trashed
95
+ end
96
+
97
+ # Undiscard the record in the database
98
+ #
99
+ # @return [Boolean] true if successful, otherwise false
100
+ def restore
101
+ return false unless trashed?
102
+ run_callbacks(:restore) do
103
+ update_attribute(self.class.soft_trash_column, nil)
104
+ end
105
+ end
106
+
107
+
108
+ def restore!
109
+ restore || _raise_record_not_restoreed
110
+ end
111
+
112
+ private
113
+
114
+ def _raise_record_not_trashed
115
+ raise ::SoftTrash::RecordNotTrasheded.new(tarshed_fail_message, self)
116
+ end
117
+
118
+ def _raise_record_not_restoreed
119
+ raise ::SoftTrash::RecordNotRecovered.new(restoreed_fail_message, self)
120
+ end
121
+
122
+ def tarshed_fail_message
123
+ return "A trash record cannot be trashed" if trashed?
124
+
125
+ "Failed to trash the record"
126
+ end
127
+
128
+ def restoreed_fail_message
129
+ return "An active record cannot be restore" if active?
130
+
131
+ "Failed to restore the record"
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,11 @@
1
+ require 'soft_trash/schema_definitions'
2
+
3
+ module SoftTrash
4
+ class Railtie < Rails::Railtie
5
+ initializer 'soft_trash.table_definition_extensions' do
6
+ ActiveSupport.on_load :active_record do
7
+ ActiveRecord::ConnectionAdapters::TableDefinition.include SoftTrash::SchemaDefinitions
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ module SoftTrash
2
+ module SchemaDefinitions
3
+ def soft_trash
4
+ column :deleted_at, :datetime, default: nil
5
+ index :deleted_at
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SoftTrash
4
+ VERSION = "0.1.0"
5
+ end
data/lib/soft_trash.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "active_record"
2
+
3
+ require "soft_trash/version"
4
+ require "soft_trash/errors"
5
+ require "soft_trash/model"
6
+ require "soft_trash/railtie" if defined?(Rails)
7
+
@@ -0,0 +1,4 @@
1
+ module SoftTrash
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soft_trash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mahendra.dabhi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-08-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sqlite3
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A Ruby gem that provides soft delete and recovery capabilities using
42
+ deleted_at timestamp
43
+ email:
44
+ - Mahendra.Dabhi@ril.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".idea/.gitignore"
50
+ - ".idea/misc.xml"
51
+ - ".idea/modules.xml"
52
+ - ".idea/soft_trash.iml"
53
+ - ".idea/vcs.xml"
54
+ - ".rspec"
55
+ - ".rubocop.yml"
56
+ - CHANGELOG.md
57
+ - CODE_OF_CONDUCT.md
58
+ - LICENSE
59
+ - LICENSE.txt
60
+ - README.md
61
+ - Rakefile
62
+ - lib/generators/soft_trash/install_generator.rb
63
+ - lib/generators/soft_trash/templates/add_deleted_at_to_tables.rb.erb
64
+ - lib/soft_trash.rb
65
+ - lib/soft_trash/errors.rb
66
+ - lib/soft_trash/model.rb
67
+ - lib/soft_trash/railtie.rb
68
+ - lib/soft_trash/schema_definitions.rb
69
+ - lib/soft_trash/version.rb
70
+ - sig/soft_trash.rbs
71
+ homepage: https://github.com/mahendraxceed/soft_trash
72
+ licenses:
73
+ - MIT
74
+ metadata:
75
+ homepage_uri: https://github.com/mahendraxceed/soft_trash
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 3.1.0
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.5.22
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Soft delete and recovery functionality for Rails models
95
+ test_files: []