Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fnando/touch
Touch a parent's collection on ActiveRecord.
https://github.com/fnando/touch
activerecord caching rails timestamp
Last synced: 28 days ago
JSON representation
Touch a parent's collection on ActiveRecord.
- Host: GitHub
- URL: https://github.com/fnando/touch
- Owner: fnando
- License: mit
- Created: 2013-07-22T21:45:54.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2018-12-27T04:59:58.000Z (almost 6 years ago)
- Last Synced: 2024-10-06T04:25:46.937Z (about 1 month ago)
- Topics: activerecord, caching, rails, timestamp
- Language: Ruby
- Size: 9.77 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Touch
[![Travis-CI](https://travis-ci.org/fnando/touch.svg)](https://travis-ci.org/fnando/touch)
[![Code Climate](https://codeclimate.com/github/fnando/touch/badges/gpa.svg)](https://codeclimate.com/github/fnando/touch)
[![Test Coverage](https://codeclimate.com/github/fnando/touch/badges/coverage.svg)](https://codeclimate.com/github/fnando/touch/coverage)
[![Gem](https://img.shields.io/gem/v/touch.svg)](https://rubygems.org/gems/touch)
[![Gem](https://img.shields.io/gem/dt/touch.svg)](https://rubygems.org/gems/touch)Touch a parent's collection on ActiveRecord.
## Why not just using `belongs_to :assoc, touch: true`?
The option provided by `belongs_to` will refresh the `updated_at` column only. With this gem, you can can have a fine control for each association, making caching easier.
## Installation
Add this line to your application's Gemfile:
gem "touch"
And then execute:
$ bundle
Or install it yourself as:
$ gem install touch
## Usage
Imagine you have to models:
```ruby
class User < ActiveRecord::Base
has_many :things
endclass Thing < ActiveRecord::Base
belongs_to :user
touch :user
end
```This new `ActiveRecord::Base.touch` method updates the `User#things_updated_at` attribute every time a new `Thing` is created, updated or removed.
It also updates the parent's `updated_at` field, just like `belongs_to :user, touch: true` configuration.
## 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