No commit activity in last 3 years
No release in over 3 years
ActiveRecord#fetch_or_initialize and ActiveRecord#fetch_or_create for IdentityCache
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

IdentityCacheFetchers Circle CI Code Climate

ActiveRecord#fetch_or_initialize and ActiveRecord#fetch_or_create for IdentityCache

# based on https://github.com/Shopify/identity_cache#secondary-indexes
class Product < ActiveRecord::Base
  include IdentityCache
  include IdentityCacheFetchers

  cache_index :handle, unique: true
  cache_index :vendor, :product_type
end

This gem brings you the equivalent of Ruby on Rails' find_or_initialize and find_or_create but uses IdentityCache as a first source:

Product.fetch_or_initialize_by(handle: "test")
Product.fetch_or_initialize_by(vendor: "Acme Corporation", product_type: "A thing")
Product.fetch_or_create_by(handle: "test")
Product.fetch_or_create_by(vendor: "Acme Corporation", product_type: "A thing")

Time to go crazy:

gem 'identity_cache_fetchers'