ActiveRecord Accessible Json
Using this gem, ActiveRecord JSON typed attribute is deserialized into HashWithIndifferentAccess if possible.
Example
# Both author and tags are JSON typed columns.
Post.create(author: { 'name': 'yamat47', 'age': 27 }, tags: %w[Rails TDD])
post = Post.last
post..class #=> ActiveSupport::HashWithIndifferentAccess
post.['name'] #=> 'yamat47'
post.['name'] == post.[:name] #=> true
post. = { name: 'Andy', age: 30 }
post..class #=> ActiveSupport::HashWithIndifferentAccess
post.['name'] #=> 'Andy'
post.['name'] == post.[:name] #=> true
# If attribute's value is not changeable into HashWithIndifferentAccess,
# this gem does nothing.
post..class #=> Array
Version Compatibility
| Rails 5.2 | Rails 6.0 | Rails 6.1 | Rails head | |
|---|---|---|---|---|
| Ruby 2.5 | ✅ | ✅ | ✅ | ❌ |
| Ruby 2.6 | ✅ | ✅ | ✅ | ❌ |
| Ruby 2.7 | ✅ | ✅ | ✅ | ✅ |
| Ruby 3.0 | ❌ | ✅ | ✅ | ✅ |
| Ruby head | ❌ | ✅ | ✅ | ✅ |
Version compatibility is checked everyday on CI.
Installation
Add this line to your Rails application's Gemfile:
gem 'activerecord_accessible_json'
And then execute:
$ bundle
Or install it yourself as:
$ gem install activerecord_accessible_json
Release
- Check if CI is passed on
main. - Decide next versioning and update version.rb.
bundle install.- Commit these changes with happy message (like "Release v0.2.0 🎉").
ghch --format=markdown --next-version={{ NEXT_VERSION }}to generate changelog.- Create new release.
bundle exec rake build.bundle exec rake release.
License
The gem is available as open source under the terms of the MIT License.