Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 1.66 KB

compiler_identitycache.md

File metadata and controls

49 lines (36 loc) · 1.66 KB

IdentityCache

Tapioca::Dsl::Compilers::IdentityCache generates RBI files for Active Record models that use include IdentityCache. IdentityCache is a blob level caching solution to plug into Active Record.

For example, with the following Active Record class:

# post.rb
class Post < ApplicationRecord
   include IdentityCache

   cache_index :blog_id
   cache_index :title, unique: true
   cache_index :title, :review_date, unique: true

end

this compiler will produce the RBI file post.rbi with the following content:

# post.rbi
# typed: true
class Post
  sig { params(blog_id: T.untyped, includes: T.untyped).returns(T::Array[::Post])
  def fetch_by_blog_id(blog_id, includes: nil); end

  sig { params(blog_ids: T.untyped, includes: T.untyped).returns(T::Array[::Post])
  def fetch_multi_by_blog_id(index_values, includes: nil); end

  sig { params(title: T.untyped, includes: T.untyped).returns(::Post) }
  def fetch_by_title!(title, includes: nil); end

  sig { params(title: T.untyped, includes: T.untyped).returns(T.nilable(::Post)) }
  def fetch_by_title(title, includes: nil); end

  sig { params(index_values: T.untyped, includes: T.untyped).returns(T::Array[::Post]) }
  def fetch_multi_by_title(index_values, includes: nil); end

  sig { params(title: T.untyped, review_date: T.untyped, includes: T.untyped).returns(T::Array[::Post]) }
  def fetch_by_title_and_review_date!(title, review_date, includes: nil); end

  sig { params(title: T.untyped, review_date: T.untyped, includes: T.untyped).returns(T::Array[::Post]) }
  def fetch_by_title_and_review_date(title, review_date, includes: nil); end
end