Skip to content

Latest commit

 

History

History
32 lines (25 loc) · 901 Bytes

compiler_activerecordscope.md

File metadata and controls

32 lines (25 loc) · 901 Bytes

ActiveRecordScope

Tapioca::Dsl::Compilers::ActiveRecordScope decorates RBI files for subclasses of ActiveRecord::Base which declare scope fields.

For example, with the following ActiveRecord::Base subclass:

class Post < ApplicationRecord
  scope :public_kind, -> { where.not(kind: 'private') }
  scope :private_kind, -> { where(kind: 'private') }
end

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

# post.rbi
# typed: true
class Post
  extend GeneratedRelationMethods

  module GeneratedRelationMethods
    sig { params(args: T.untyped, blk: T.untyped).returns(T.untyped) }
    def private_kind(*args, &blk); end

    sig { params(args: T.untyped, blk: T.untyped).returns(T.untyped) }
    def public_kind(*args, &blk); end
  end
end