Sha256: 5d6ea0880e3497fc0f33368b079f44d5942611f3210c02098d774a852d894025

Contents?: true

Size: 1.94 KB

Versions: 2

Compression:

Stored size: 1.94 KB

Contents

# acts_as_removable

This gem allows you to easily manage ActiveRecord objects that are pseudo destroyed a.k.a. removed.

## Installation

Add this line to your application's Gemfile:

    gem 'acts_as_removable'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install acts_as_removable

## Usage

```ruby
# a column removed_at of type timestamp is required
class MyModel < ActiveRecord::Base
  acts_as_removable
end

record = MyModel.create
record.removed? # => false
record.remove
record.removed? # => true
```

You can also specify the column to use:
```ruby
class MyModel < ActiveRecord::Base
  acts_as_removable column_name: :some_column
end
```

It's possible to add a default scope with the active (not removed) records:
```ruby
class MyModel < ActiveRecord::Base
  acts_as_removable with_default_scope: true
end
```

And you can use callbacks:
```ruby
class MyModel < ActiveRecord::Base
  acts_as_removable

  before_remove do |r|
    puts "Before removing record"
  end

  after_remove :after_remove_method
  def after_remove_method
    puts "After removing record"
  end

  before_unremove do |r|
    puts "Before unremoving record"
  end

  after_unremove :after_unremove_method
  def after_unremove_method
    puts "After unremoving record"
  end
end
```

## Code Status

* [![Build Status](https://api.travis-ci.org/SICSoftwareGmbH/acts_as_removable.png)](https://travis-ci.org/SICSoftwareGmbH/acts_as_removable)
* [![Dependencies](https://gemnasium.com/SICSoftwareGmbH/acts_as_removable.png?travis)](https://gemnasium.com/SICSoftwareGmbH/acts_as_removable)
* [![Code Climate](https://codeclimate.com/github/SICSoftwareGmbH/acts_as_removable.png)](https://codeclimate.com/github/SICSoftwareGmbH/acts_as_removable)

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
acts_as_removable-1.1.0 README.md
acts_as_removable-1.0.0 README.md