store_attribute

ActiveRecord extension which adds typecasting to store accessors

MIT License

Downloads
654.2K
Stars
387
Committers
13

Bot releases are hidden (Show)

store_attribute - 1.1.0 Latest Release

Published by palkan over 1 year ago

Features

  • Added configuration option to return default values when attribute key is not present in the serialized value.
class ApplicationRecord < ActiveRecord::Base
  self.store_attribute_unset_values_fallback_to_default = true

  store_attribute :extra, :color, :string, default: "grey"
end

user = User.create!(extra: {})
# without the fallback
user.color #=> nil
# with fallback
user.color #=> "grey"
store_attribute - 1.0.0

Published by palkan over 2 years ago

This release bring major improvements to the way we interact with ActiveRecord:

  • Use existing Attributes API and Store API instead of duplicating and monkey-patching
  • Dirty-tracking, accessors and prefixes/suffixes are now handled by Rails—we're no longer trying to re-implement this.

Thus, we only provide type coercions for stores. That's it.

P.S. The only internal patch that's left is the MutationTracker patch which allows you to have granular #changes for stores.

Package Rankings
Top 5.94% on Rubygems.org
Badges
Extracted from project README
Cult Of Martians Gem Version
Related Projects