### Getting Started Command Source: https://github.com/shopify/tapioca/blob/main/README.md Execute this command to initialize Tapioca and prepare your project for type checking. ```shell $ bundle exec tapioca init ``` -------------------------------- ### Example Configuration and Generated RBI Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_config.md Demonstrates how a YAML configuration file and a Ruby Config setup result in a generated RBI file. ```yaml --- github: token: 12345 client_id: 54321 client_secret: super_secret ``` ```ruby Config.setup do |config| config.const_name = "AppSettings" end ``` ```rbi AppSettings = T.let(T.unsafe(nil), AppSettingsConfigOptions) class AppSettingsConfigOptions < ::Config::Options sig { returns(T.untyped) } def github; end sig { params(value: T.untyped).returns(T.untyped) } def github=(value); end end ``` -------------------------------- ### Example Controller Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_actioncontrollerhelpers.md An example of a controller that uses helper methods. ```ruby class UserController < ActionController::Base helper MyHelper helper { def age(user) "99" end } helper_method :current_user_name def current_user_name # ... end end ``` -------------------------------- ### Example Helper Module Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_actioncontrollerhelpers.md An example of a helper module that can be used with ActionControllerHelpers. ```ruby module MyHelper def greet(user) # ... end def localized_time # ... end end ``` -------------------------------- ### Example Post Class Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_smartproperties.md An example of a Ruby class that includes SmartProperties. ```ruby # post.rb class Post include(SmartProperties) property :title, accepts: String property! :description, accepts: String property :published, accepts: [true, false], reader: :published? property :enabled, accepts: [true, false], default: false end ``` -------------------------------- ### Example Post Model Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_activerecordrelations.md Example of an ActiveRecord::Base subclass and the generated RBI file content. ```ruby class Post < ApplicationRecord end ``` ```rbi # post.rbi # synthetic class for Post module Post::GeneratedRelationMethods def all: () ->(Post::PrivateRelation) end def "find_by!": () ->(Post) end def "find_by": () ->(Post?) end def "where": (**kwargs) -> (Post::PrivateRelation) def "or": (other) -> (Post::PrivateRelation) def "not": (**kwargs) -> (Post::PrivateRelation) def "rewhere": (**kwargs) -> (Post::PrivateRelation) def "order": (*args) -> (Post::PrivateRelation) def "order!`: (*args) -> (Post::PrivateRelation) def "order_as_relative!": (*args) -> (Post::PrivateRelation) def "order_as_relative": (*args) -> (Post::PrivateRelation) def "reorder": (*args) -> (Post::PrivateRelation) def "reorder!": (*args) -> (Post::PrivateRelation) def "limit": (limit) -> (Post::PrivateRelation) def "limit!": (limit) -> (Post::PrivateRelation) def "offset": (offset) -> (Post::PrivateRelation) def "offset!": (offset) -> (Post::PrivateRelation) def "first": (limit = nil) -> (Post | Post?) def "first!": (limit = nil) -> (Post | Post?) def "last": (limit = nil) -> (Post | Post?) def "last!": (limit = nil) -> (Post | Post?) def "find": (*args) -> (Post | Post?) def "find!": (*args) -> (Post) def "take": (limit = nil) -> (Post | Post?) def "take!": (limit = nil) -> (Post) def "none": () -> (Post::PrivateRelation) def "unscope": (**kwargs) -> (Post::PrivateRelation) def "unscope!": (**kwargs) -> (Post::PrivateRelation) def "only": (**kwargs) -> (Post::PrivateRelation) def "only!": (**kwargs) -> (Post::PrivateRelation) def "except": (**kwargs) -> (Post::PrivateRelation) def "except!": (**kwargs) -> (Post::PrivateRelation) def "skip": (**kwargs) -> (Post::PrivateRelation) def "skip!": (**kwargs) -> (Post::PrivateRelation) def "extending": (*modules) { (*args) -> (Post::PrivateRelation) } def "extending!": (*modules) { (*args) -> (Post::PrivateRelation) } def "extending": (*modules) -> (Post::PrivateRelation) def "extending!": (*modules) -> (Post::PrivateRelation) def "merge": (other) -> (Post::PrivateRelation) def "merge!": (other) -> (Post::PrivateRelation) def "none!": () -> (Post::PrivateRelation) def "create!": (**kwargs) -> (Post) def "create": (**kwargs) -> (Post?) def "build": (**kwargs) -> (Post) def "count": (*args) -> (Integer) def "destroy_all": (*args) -> (Array) def "destroy_by": (**kwargs) -> (Array) def "exists?": (*args) -> (Boolean) def "find_each": (*args) { (Post) -> (Enumerator) } def "find_in_batches": (*args) { (Array) -> (Enumerator) } def "pluck": (*args) -> (Array) def "select": (*args) -> (Post::PrivateRelation) def "select!": (*args) -> (Post::PrivateRelation) def "group": (*args) -> (Post::PrivateRelation) def "group!": (*args) -> (Post::PrivateRelation) def "having": (*args) -> (Post::PrivateRelation) def "having!": (*args) -> (Post::PrivateRelation) def "distinct": (*args) -> (Post::PrivateRelation) def "distinct!": (*args) -> (Post::PrivateRelation) def "left_outer_joins": (*args) -> (Post::PrivateRelation) def "left_outer_joins!": (*args) -> (Post::PrivateRelation) def "left_joins": (*args) -> (Post::PrivateRelation) def "left_joins!": (*args) -> (Post::PrivateRelation) def "right_outer_joins": (*args) -> (Post::PrivateRelation) def "right_outer_joins!": (*args) -> (Post::PrivateRelation) def "right_joins": (*args) -> (Post::PrivateRelation) def "right_joins!": (*args) -> (Post::PrivateRelation) def "inner_joins": (*args) -> (Post::PrivateRelation) def "inner_joins!": (*args) -> (Post::PrivateRelation) def "joins": (*args) -> (Post::PrivateRelation) def "joins!": (*args) -> (Post::PrivateRelation) def "eager_load": (*args) -> (Post::PrivateRelation) def "eager_load!": (*args) -> (Post::PrivateRelation) def "preload": (*args) -> (Post::PrivateRelation) def "preload!": (*args) -> (Post::PrivateRelation) def "includes": (*args) -> (Post::PrivateRelation) def "includes!": (*args) -> (Post::PrivateRelation) def "references": (*args) -> (Post::PrivateRelation) def "references!": (*args) -> (Post::PrivateRelation) def "none!": () -> (Post::PrivateRelation) def "from": (*args) -> (Post::PrivateRelation) def "from!": (*args) -> (Post::PrivateRelation) def "readonly": (*args) -> (Post::PrivateRelation) def "readonly!": (*args) -> (Post::PrivateRelation) def "deep_clone": (*args) -> (Post::PrivateRelation) def "deep_clone!": (*args) -> (Post::PrivateRelation) def "annotate": (*args) -> (Post::PrivateRelation) def "annotate!": (*args) -> (Post::PrivateRelation) def "optimizer_hints": (*args) -> (Post::PrivateRelation) def "optimizer_hints!": (*args) -> (Post::PrivateRelation) def "strict_loading": (*args) -> (Post::PrivateRelation) def "strict_loading!": (*args) -> (Post::PrivateRelation) def "invert_where": () -> (Post::PrivateRelation) def "invert_where!": () -> (Post::PrivateRelation) def "except": (**kwargs) -> (Post::PrivateRelation) def "except!": (**kwargs) -> (Post::PrivateRelation) def "skip": (**kwargs) -> (Post::PrivateRelation) def "skip!": (**kwargs) -> (Post::PrivateRelation) def "extending": (*modules) { (*args) -> (Post::PrivateRelation) } def "extending!": (*modules) { (*args) -> (Post::PrivateRelation) } def "extending": (*modules) -> (Post::PrivateRelation) def "extending!": (*modules) -> (Post::PrivateRelation) def "merge": (other) -> (Post::PrivateRelation) def "merge!": (other) -> (Post::PrivateRelation) def "none!": () -> (Post::PrivateRelation) def "create!": (**kwargs) -> (Post) def "create": (**kwargs) -> (Post?) def "build": (**kwargs) -> (Post) def "count": (*args) -> (Integer) def "destroy_all": (*args) -> (Array) def "destroy_by": (**kwargs) -> (Array) def "exists?": (*args) -> (Boolean) def "find_each": (*args) { (Post) -> (Enumerator) } def "find_in_batches": (*args) { (Array) -> (Enumerator) } def "pluck": (*args) -> (Array) def "select": (*args) -> (Post::PrivateRelation) def "select!": (*args) -> (Post::PrivateRelation) def "group": (*args) -> (Post::PrivateRelation) def "group!": (*args) -> (Post::PrivateRelation) def "having": (*args) -> (Post::PrivateRelation) def "having!": (*args) -> (Post::PrivateRelation) def "distinct": (*args) -> (Post::PrivateRelation) def "distinct!": (*args) -> (Post::PrivateRelation) def "left_outer_joins": (*args) -> (Post::PrivateRelation) def "left_outer_joins!": (*args) -> (Post::PrivateRelation) def "left_joins": (*args) -> (Post::PrivateRelation) def "left_joins!": (*args) -> (Post::PrivateRelation) def "right_outer_joins": (*args) -> (Post::PrivateRelation) def "right_outer_joins!": (*args) -> (Post::PrivateRelation) def "right_joins": (*args) -> (Post::PrivateRelation) def "right_joins!": (*args) -> (Post::PrivateRelation) def "inner_joins": (*args) -> (Post::PrivateRelation) def "inner_joins!": (*args) -> (Post::PrivateRelation) def "joins": (*args) -> (Post::PrivateRelation) def "joins!": (*args) -> (Post::PrivateRelation) def "eager_load": (*args) -> (Post::PrivateRelation) def "eager_load!": (*args) -> (Post::PrivateRelation) def "preload": (*args) -> (Post::PrivateRelation) def "preload!": (*args) -> (Post::PrivateRelation) def "includes": (*args) -> (Post::PrivateRelation) def "includes!": (*args) -> (Post::PrivateRelation) def "references": (*args) -> (Post::PrivateRelation) def "references!": (*args) -> (Post::PrivateRelation) def "none!": () -> (Post::PrivateRelation) def "from": (*args) -> (Post::PrivateRelation) def "from!": (*args) -> (Post::PrivateRelation) def "readonly": (*args) -> (Post::PrivateRelation) def "readonly!": (*args) -> (Post::PrivateRelation) def "deep_clone": (*args) -> (Post::PrivateRelation) def "deep_clone!": (*args) -> (Post::PrivateRelation) def "annotate": (*args) -> (Post::PrivateRelation) def "annotate!": (*args) -> (Post::PrivateRelation) def "optimizer_hints": (*args) -> (Post::PrivateRelation) def "optimizer_hints!": (*args) -> (Post::PrivateRelation) def "strict_loading": (*args) -> (Post::PrivateRelation) def "strict_loading!": (*args) -> (Post::PrivateRelation) def "invert_where": () -> (Post::PrivateRelation) def "invert_where!": () -> (Post::PrivateRelation) end module Post::GeneratedAssociationRelationMethods def all: () ->(Post::PrivateAssociationRelation) end def "find_by!": () ->(Post) end def "find_by": () ->(Post?) end def "where": (**kwargs) -> (Post::PrivateAssociationRelation) def "or": (other) -> (Post::PrivateAssociationRelation) def "not": (**kwargs) -> (Post::PrivateAssociationRelation) def "rewhere": (**kwargs) -> (Post::PrivateAssociationRelation) def "order": (*args) -> (Post::PrivateAssociationRelation) def "order!`: (*args) -> (Post::PrivateAssociationRelation) def "order_as_relative!": (*args) -> (Post::PrivateAssociationRelation) def "order_as_relative": (*args) -> (Post::PrivateAssociationRelation) def "reorder": (*args) -> (Post::PrivateAssociationRelation) def "reorder!": (*args) -> (Post::PrivateAssociationRelation) def "limit": (limit) -> (Post::PrivateAssociationRelation) def "limit!": (limit) -> (Post::PrivateAssociationRelation) def "offset": (offset) -> (Post::PrivateAssociationRelation) def "offset!": (offset) -> (Post::PrivateAssociationRelation) def "first": (limit = nil) -> (Post | Post?) def "first!": (limit = nil) -> (Post | Post?) def "last": (limit = nil) -> (Post | Post?) def "last!": (limit = nil) -> (Post | Post?) def "find": (*args) -> (Post | Post?) def "find!": (*args) -> (Post) def "take": (limit = nil) -> (Post | Post?) def "take!": (limit = nil) -> (Post) def "none": () -> (Post::PrivateAssociationRelation) def "unscope": (**kwargs) -> (Post::PrivateAssociationRelation) def "unscope!": (**kwargs) -> (Post::PrivateAssociationRelation) def "only": (**kwargs) -> (Post::PrivateAssociationRelation) def "only!": (**kwargs) -> (Post::PrivateAssociationRelation) def "except": (**kwargs) -> (Post::PrivateAssociationRelation) def "except!": (**kwargs) -> (Post::PrivateAssociationRelation) def "skip": (**kwargs) -> (Post::PrivateAssociationRelation) def "skip!": (**kwargs) -> (Post::PrivateAssociationRelation) def "extending": (*modules) { (*args) -> (Post::PrivateAssociationRelation) } def "extending!": (*modules) { (*args) -> (Post::PrivateAssociationRelation) } def "extending": (*modules) -> (Post::PrivateAssociationRelation) def "extending!": (*modules) -> (Post::PrivateAssociationRelation) def "merge": (other) -> (Post::PrivateAssociationRelation) def "merge!": (other) -> (Post::PrivateAssociationRelation) def "none!": () -> (Post::PrivateAssociationRelation) def "create!": (**kwargs) -> (Post) def "create": (**kwargs) -> (Post?) def "build": (**kwargs) -> (Post) def "count": (*args) -> (Integer) def "destroy_all": (*args) -> (Array) def "destroy_by": (**kwargs) -> (Array) def "exists?": (*args) -> (Boolean) def "find_each": (*args) { (Post) -> (Enumerator) } def "find_in_batches": (*args) { (Array) -> (Enumerator) } def "pluck": (*args) -> (Array) def "select": (*args) -> (Post::PrivateAssociationRelation) def "select!": (*args) -> (Post::PrivateAssociationRelation) def "group": (*args) -> (Post::PrivateAssociationRelation) def "group!": (*args) -> (Post::PrivateAssociationRelation) def "having": (*args) -> (Post::PrivateAssociationRelation) def "having!": (*args) -> (Post::PrivateAssociationRelation) def "distinct": (*args) -> (Post::PrivateAssociationRelation) def "distinct!": (*args) -> (Post::PrivateAssociationRelation) def "left_outer_joins": (*args) -> (Post::PrivateAssociationRelation) def "left_outer_joins!": (*args) -> (Post::PrivateAssociationRelation) def "left_joins": (*args) -> (Post::PrivateAssociationRelation) def "left_joins!": (*args) -> (Post::PrivateAssociationRelation) def "right_outer_joins": (*args) -> (Post::PrivateAssociationRelation) def "right_outer_joins!": (*args) -> (Post::PrivateAssociationRelation) def "right_joins": (*args) -> (Post::PrivateAssociationRelation) def "right_joins!": (*args) -> (Post::PrivateAssociationRelation) def "inner_joins": (*args) -> (Post::PrivateAssociationRelation) def "inner_joins!": (*args) -> (Post::PrivateAssociationRelation) def "joins": (*args) -> (Post::PrivateAssociationRelation) def "joins!": (*args) -> (Post::PrivateAssociationRelation) def "eager_load": (*args) -> (Post::PrivateAssociationRelation) def "eager_load!": (*args) -> (Post::PrivateAssociationRelation) def "preload": (*args) -> (Post::PrivateAssociationRelation) def "preload!": (*args) -> (Post::PrivateAssociationRelation) def "includes": (*args) -> (Post::PrivateAssociationRelation) def "includes!": (*args) -> (Post::PrivateAssociationRelation) def "references": (*args) -> (Post::PrivateAssociationRelation) def "references!": (*args) -> (Post::PrivateAssociationRelation) def "none!": () -> (Post::PrivateAssociationRelation) def "from": (*args) -> (Post::PrivateAssociationRelation) def "from!": (*args) -> (Post::PrivateAssociationRelation) def "readonly": (*args) -> (Post::PrivateAssociationRelation) def "readonly!": (*args) -> (Post::PrivateAssociationRelation) def "deep_clone": (*args) -> (Post::PrivateAssociationRelation) def "deep_clone!": (*args) -> (Post::PrivateAssociationRelation) def "annotate": (*args) -> (Post::PrivateAssociationRelation) def "annotate!": (*args) -> (Post::PrivateAssociationRelation) def "optimizer_hints": (*args) -> (Post::PrivateAssociationRelation) def "optimizer_hints!": (*args) -> (Post::PrivateAssociationRelation) def "strict_loading": (*args) -> (Post::PrivateAssociationRelation) def "strict_loading!": (*args) -> (Post::PrivateAssociationRelation) def "invert_where": () -> (Post::PrivateAssociationRelation) def "invert_where!": () -> (Post::PrivateAssociationRelation) end module Post::CommonRelationMethods def "find_by!": () ->(Post) end def "find_by": () ->(Post?) end def "where": (**kwargs) -> (Post::PrivateRelation) def "or": (other) -> (Post::PrivateRelation) def "not": (**kwargs) -> (Post::PrivateRelation) def "rewhere": (**kwargs) -> (Post::PrivateRelation) def "order": (*args) -> (Post::PrivateRelation) def "order!`: (*args) -> (Post::PrivateRelation) def "order_as_relative!": (*args) -> (Post::PrivateRelation) def "order_as_relative": (*args) -> (Post::PrivateRelation) def "reorder": (*args) -> (Post::PrivateRelation) def "reorder!": (*args) -> (Post::PrivateRelation) def "limit": (limit) -> (Post::PrivateRelation) def "limit!": (limit) -> (Post::PrivateRelation) def "offset": (offset) -> (Post::PrivateRelation) def "offset!": (offset) -> (Post::PrivateRelation) def "first": (limit = nil) -> (Post | Post?) def "first!": (limit = nil) -> (Post | Post?) def "last": (limit = nil) -> (Post | Post?) def "last!": (limit = nil) -> (Post | Post?) def "find": (*args) -> (Post | Post?) def "find!": (*args) -> (Post) def "take": (limit = nil) -> (Post | Post?) def "take!": (limit = nil) -> (Post) def "none": () -> (Post::PrivateRelation) def "unscope": (**kwargs) -> (Post::PrivateRelation) def "unscope!": (**kwargs) -> (Post::PrivateRelation) def "only": (**kwargs) -> (Post::PrivateRelation) def "only!": (**kwargs) -> (Post::PrivateRelation) def "except": (**kwargs) -> (Post::PrivateRelation) def "except!": (**kwargs) -> (Post::PrivateRelation) def "skip": (**kwargs) -> (Post::PrivateRelation) def "skip!": (**kwargs) -> (Post::PrivateRelation) def "extending": (*modules) { (*args) -> (Post::PrivateRelation) } def "extending!": (*modules) { (*args) -> (Post::PrivateRelation) } def "extending": (*modules) -> (Post::PrivateRelation) def "extending!": (*modules) -> (Post::PrivateRelation) def "merge": (other) -> (Post::PrivateRelation) def "merge!": (other) -> (Post::PrivateRelation) def "none!": () -> (Post::PrivateRelation) def "create!": (**kwargs) -> (Post) def "create": (**kwargs) -> (Post?) def "build": (**kwargs) -> (Post) def "count": (*args) -> (Integer) def "destroy_all": (*args) -> (Array) def "destroy_by": (**kwargs) -> (Array) def "exists?": (*args) -> (Boolean) def "find_each": (*args) { (Post) -> (Enumerator) } def "find_in_batches": (*args) { (Array) -> (Enumerator) } def "pluck": (*args) -> (Array) def "select": (*args) -> (Post::PrivateRelation) def "select!": (*args) -> (Post::PrivateRelation) def "group": (*args) -> (Post::PrivateRelation) def "group!": (*args) -> (Post::PrivateRelation) def "having": (*args) -> (Post::PrivateRelation) def "having!": (*args) -> (Post::PrivateRelation) def "distinct": (*args) -> (Post::PrivateRelation) def "distinct!": (*args) -> (Post::PrivateRelation) def "left_outer_joins": (*args) -> (Post::PrivateRelation) def "left_outer_joins!": (*args) -> (Post::PrivateRelation) def "left_joins": (*args) -> (Post::PrivateRelation) def "left_joins!": (*args) -> (Post::PrivateRelation) def "right_outer_joins": (*args) -> (Post::PrivateRelation) def "right_outer_joins!": (*args) -> (Post::PrivateRelation) def "right_joins": (*args) -> (Post::PrivateRelation) def "right_joins!": (*args) -> (Post::PrivateRelation) def "inner_joins": (*args) -> (Post::PrivateRelation) def "inner_joins!": (*args) -> (Post::PrivateRelation) def "joins": (*args) -> (Post::PrivateRelation) def "joins!": (*args) -> (Post::PrivateRelation) def "eager_load": (*args) -> (Post::PrivateRelation) def "eager_load!": (*args) -> (Post::PrivateRelation) def "preload": (*args) -> (Post::PrivateRelation) def "preload!": (*args) -> (Post::PrivateRelation) def "includes": (*args) -> (Post::PrivateRelation) def "includes!": (*args) -> (Post::PrivateRelation) def "references": (*args) -> (Post::PrivateRelation) def "references!": (*args) -> (Post::PrivateRelation) def "none!": () -> (Post::PrivateRelation) def "from": (*args) -> (Post::PrivateRelation) def "from!": (*args) -> (Post::PrivateRelation) def "readonly": (*args) -> (Post::PrivateRelation) def "readonly!": (*args) -> (Post::PrivateRelation) def "deep_clone": (*args) -> (Post::PrivateRelation) def "deep_clone!": (*args) -> (Post::PrivateRelation) def "annotate": (*args) -> (Post::PrivateRelation) def "annotate!": (*args) -> (Post::PrivateRelation) def "optimizer_hints": (*args) -> (Post::PrivateRelation) def "optimizer_hints!": (*args) -> (Post::PrivateRelation) def "strict_loading": (*args) -> (Post::PrivateRelation) def "strict_loading!": (*args) -> (Post::PrivateRelation) def "invert_where": () -> (Post::PrivateRelation) def "invert_where!": () -> (Post::PrivateRelation) end ``` -------------------------------- ### Application Configuration Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_urlhelpers.md Example of setting up routes in config/application.rb. ```ruby class Application < Rails::Application routes.draw do resource :index end end ``` -------------------------------- ### Example Database Schema Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_activerecordcolumns.md An example of a database schema for the Post model. ```ruby # db/schema.rb create_table :posts do |t| t.string :title, null: false t.string :body t.boolean :published t.timestamps end ``` -------------------------------- ### GraphQL::Schema::InputObject subclass example Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_graphqlinputobject.md An example of a GraphQL::Schema::InputObject subclass. ```ruby class CreateCommentInput < GraphQL::Schema::InputObject argument :body, String, required: true argument :post_id, ID, required: true end ``` -------------------------------- ### Example sorbet/tapioca/require.rb file Source: https://github.com/shopify/tapioca/blob/main/README.md An example of what the sorbet/tapioca/require.rb file might look like, including requires for various libraries. ```ruby # typed: strict # frozen_string_literal: true require "ansi/code" require "google/protobuf" require "rails/all" require "rails/generators" require "rails/generators/app_base" require "rake/testtask" require "rubocop/rake_task" ``` -------------------------------- ### Gem RBI Generation Example Source: https://github.com/shopify/tapioca/blob/main/README.md Example command executed by Tapioca when changes are made to Gemfile.lock. ```bash bin/tapioca gem my_gem ``` -------------------------------- ### Example YAML Fixture Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_activerecordfixtures.md An example of a Rails fixture file in YAML format. ```yaml first_post: author: John title: My post ``` -------------------------------- ### Example User and Post Classes Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_jsonapiclientresource.md Demonstrates classes that inherit from JsonApiClient::Resource. ```ruby # user.rb class User < JsonApiClient::Resource has_many :posts property :name, type: :string property :is_admin, type: :boolean, default: false end # post.rb class Post < JsonApiClient::Resource belongs_to :user property :title, type: :string end ``` -------------------------------- ### Example of DSL usage Source: https://github.com/shopify/tapioca/wiki/Migrating-to-Tapioca An example demonstrating how `belongs_to` in a Rails model creates methods that Tapioca can generate RBIs for. ```ruby class Post < ApplicationRecord # Belongs to will create a few methods in this class # to be able to access the associated author. Sorbet # does not know about them, since they only exist during # runtime. Tapioca can generate the definitions in RBIs # for methods like this one. belongs_to :author end ``` -------------------------------- ### Example Model Class Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_activerecordcolumns.md An example of an Active Record model class. ```ruby class Post < ActiveRecord::Base end ``` -------------------------------- ### Example ActiveRecord Class Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_activerecordtypedstore.md An example of an ActiveRecord class using the typed_store feature. ```ruby class Post < ApplicationRecord typed_store :metadata do |s| s.string(:reviewer, blank: false, accessor: false) s.date(:review_date) s.boolean(:reviewed, null: false, default: false) end end ``` -------------------------------- ### Example ActiveRecord Class Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_activerecordstore.md This is an example of a Ruby class that uses ActiveRecord::Store. ```ruby class User < ActiveRecord::Base store :settings, accessors: :theme store_accessor :settings, :power_source, prefix: :prefs end ``` -------------------------------- ### Example User Class Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_activerecordsecuretoken.md An example of a Ruby class using ActiveRecord::SecureToken with default and custom token names. ```ruby class User < ActiveRecord::Base has_secure_token has_secure_token :auth_token, length: 36 end ``` -------------------------------- ### DSL RBI Generation Example Source: https://github.com/shopify/tapioca/blob/main/README.md Example command executed by Tapioca when editing a Ruby file. ```bash bin/tapioca dsl MyClass ``` -------------------------------- ### Example cart.rb file Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_protobuf.md An example of a Ruby file defining a Protobuf message structure. ```ruby Google::Protobuf::DescriptorPool.generated_pool.build do add_file("cart.proto", :syntax => :proto3) do add_message "MyCart" do optional :shop_id, :int32, 1 optional :customer_id, :int64, 2 optional :number_value, :double, 3 optional :string_value, :string, 4 end end end ``` -------------------------------- ### Using multiple custom repositories Source: https://github.com/shopify/tapioca/blob/main/README.md Example of pulling annotations from multiple custom sources. ```shell $ bin/tapioca annotations --sources https://raw.githubusercontent.com/$USER/$REPO1/$BRANCH https://raw.githubusercontent.com/$USER/$REPO2/$BRANCH ``` -------------------------------- ### ActiveJob Subclass Example Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_activejob.md An example of an ActiveJob subclass written in Ruby. ```ruby class NotifyUserJob < ActiveJob::Base sig { params(user: User).returns(Mail) } def perform(user) # ... end end ``` -------------------------------- ### Example Vehicle Class Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_statemachines.md An example of a Ruby class using the state_machine gem. ```ruby class Vehicle state_machine :alarm_state, initial: :active, namespace: :'alarm' do event :enable do transition all => :active end event :disable do transition all => :off end state :active, :value => 1 state :off, :value => 0 end end ``` -------------------------------- ### Using a custom remote repository Source: https://github.com/shopify/tapioca/blob/main/README.md Example of using a custom repository for annotations. ```shell $ bin/tapioca annotations --sources https://raw.githubusercontent.com/$USER/$REPO/$BRANCH ``` -------------------------------- ### Using a local directory as a source Source: https://github.com/shopify/tapioca/blob/main/README.md Example of specifying a local directory as a source for annotations. ```shell $ bin/tapioca annotations --sources path/to/folder ``` -------------------------------- ### GraphQL::Schema::Mutation Subclass Example Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_graphqlmutation.md An example of a GraphQL::Schema::Mutation subclass. ```ruby class CreateComment < GraphQL::Schema::Mutation argument :body, String, required: true argument :post_id, ID, required: true def resolve(body:, post_id:) # ... end end ``` -------------------------------- ### Example ActiveRecord Model Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_activerecordassociations.md An example of an ActiveRecord model class with various associations defined. ```ruby class Post < ActiveRecord::Base belongs_to :category has_many :comments has_one :author, class_name: "User" accepts_nested_attributes_for :category, :comments, :author end ``` -------------------------------- ### Example YAML Data Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_frozenrecord.md A sample YAML file containing data for FrozenRecord objects. ```yaml # students.yml - id: 1 first_name: John last_name: Smith - id: 2 first_name: Dan last_name: Lord ``` -------------------------------- ### Specifying a custom .netrc file Source: https://github.com/shopify/tapioca/blob/main/README.md Example of specifying a custom .netrc file path. ```shell $ bin/tapioca annotations --netrc-file /path/to/my/netrc/file ``` -------------------------------- ### Example FrozenRecord Class Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_frozenrecord.md A sample Ruby class that inherits from FrozenRecord::Base. ```ruby # student.rb class Student < FrozenRecord::Base end ``` -------------------------------- ### Concern Example Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_mixedinclassattributes.md An example of a concern that uses class_attribute. ```ruby module Taggeable extend ActiveSupport::Concern included do class_attribute :tag end end ``` -------------------------------- ### Tapioca Init Command Help Source: https://github.com/shopify/tapioca/blob/main/README.md Provides detailed usage information for the `tapioca init` command. ```shell $ tapioca help init Usage: tapioca init Options: -c, [--config=] # Path to the Tapioca configuration file # Default: sorbet/tapioca/config.yml -V, [--verbose], [--no-verbose], [--skip-verbose] # Verbose output for debugging purposes # Default: false Get project ready for type checking ``` -------------------------------- ### Tapioca Commands Help Source: https://github.com/shopify/tapioca/blob/main/README.md Lists all available commands and options for the Tapioca CLI. ```shell $ tapioca help Commands: tapioca --version, -v # Show version tapioca annotations # Pull gem RBI annotations from remote sources tapioca check-shims # Check duplicated definitions in shim RBIs tapioca configure # Initialize folder structure and type checking configuration tapioca dsl [constant...] # Generate RBIs for dynamic methods tapioca gem [gem...] # Generate RBIs from gems tapioca help [COMMAND] # Describe available commands or one specific command tapioca init # Get project ready for type checking tapioca require # Generate the list of files to be required by tapioca tapioca todo # Generate the list of unresolved constants tapioca tree # Print a tree of all available commands Options: -c, [--config=] # Path to the Tapioca configuration file # Default: sorbet/tapioca/config.yml -V, [--verbose], [--no-verbose], [--skip-verbose] # Verbose output for debugging purposes # Default: false ``` -------------------------------- ### ActionMailer Subclass Example Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_actionmailer.md An example of an ActionMailer subclass that the compiler processes. ```ruby class NotifierMailer < ActionMailer::Base def notify_customer(customer_id) # ... end end ``` -------------------------------- ### Gate host's Bootsnap.setup on TAPIOCA_RBS_CACHE Source: https://github.com/shopify/tapioca/blob/main/README.md Rails apps gate Bootsnap.setup on the TAPIOCA_RBS_CACHE environment variable in config/boot.rb to avoid conflicts. ```ruby require "bootsnap/setup" unless ENV["TAPIOCA_RBS_CACHE"] == "1" ``` -------------------------------- ### Tapioca DSL command help Source: https://github.com/shopify/tapioca/blob/main/README.md Help output for the 'tapioca dsl' command, detailing its usage and options. ```shell $ tapioca help dsl Usage: tapioca dsl [constant...] Options: --out, -o, [--outdir=directory] # The output directory for generated DSL RBI files # Default: sorbet/rbi/dsl [--file-header], [--no-file-header], [--skip-file-header] # Add a "This file is generated" header on top of each generated RBI file # Default: true [--only=compiler [compiler ...]] # Only run supplied DSL compiler(s) [--exclude=compiler [compiler ...]] # Exclude supplied DSL compiler(s) [--verify], [--no-verify], [--skip-verify] # Verifies RBIs are up-to-date # Default: false [--only-bootsnap-rbs-cache], [--no-only-bootsnap-rbs-cache], [--skip-only-bootsnap-rbs-cache] # Only boot the application and load DSL extensions/compilers to populate the bootsnap iseq cache, then exit. Skips compiler execution and RBI generation. Mutually exclusive with --verify and --list-compilers. # Default: false -q, [--quiet], [--no-quiet], [--skip-quiet] # Suppresses file creation output # Default: false -w, [--workers=N] # Number of parallel workers to use when generating RBIs (default: auto) [--rbi-max-line-length=N] # Set the max line length of generated RBIs. Signatures longer than the max line length will be wrapped # Default: 120 -e, [--environment=ENVIRONMENT] # The Rack/Rails environment to use when generating RBIs # Default: development -l, [--list-compilers], [--no-list-compilers], [--skip-list-compilers] # List all loaded compilers # Default: false [--app-root=APP_ROOT] # The path to the Rails application # Default: . [--halt-upon-load-error], [--no-halt-upon-load-error], [--skip-halt-upon-load-error] # Halt upon a load error while loading the Rails application # Default: true [--skip-constant=constant [constant ...]] # Do not generate RBI definitions for the given application constant(s) [--compiler-options=key:value] # Options to pass to the DSL compilers -c, [--config=] # Path to the Tapioca configuration file ``` -------------------------------- ### Tapioca gem help command Source: https://github.com/shopify/tapioca/blob/main/README.md Detailed usage and options for the `tapioca gem` command, including output directory, file headers, exclusion of gems, and inclusion of dependencies. ```shell Usage: tapioca gem [gem...] Options: --out, -o, [--outdir=directory] # The output directory for generated gem RBI files # Default: sorbet/rbi/gems [--file-header], [--no-file-header], [--skip-file-header] # Add a "This file is generated" header on top of each generated RBI file # Default: true [--all], [--no-all], [--skip-all] # Regenerate RBI files for all gems # Default: false --pre, -b, [--prerequire=file] # A file to be required before Bundler.require is called --post, -a, [--postrequire=file] # A file to be required after Bundler.require is called # Default: sorbet/tapioca/require.rb -x, [--exclude=gem [gem ...]] # Exclude the given gem(s) from RBI generation [--include-dependencies], [--no-include-dependencies], [--skip-include-dependencies] # Generate RBI files for dependencies of the given gem(s) # Default: false --typed, -t, [--typed-overrides=gem:level [gem:level ...]] # Override for typed sigils for generated gem RBIs # Default: {"activesupport" => "false"} [--verify], [--no-verify], [--skip-verify] # Verify RBIs are up-to-date # Default: false [--doc], [--no-doc], [--skip-doc] # Include documentation from sources when generating RBIs # Default: true [--loc], [--no-loc], [--skip-loc] # Include comments with source location when generating RBIs # Default: true [--exported-gem-rbis], [--no-exported-gem-rbis], [--skip-exported-gem-rbis] # Include RBIs found in the `rbi/` directory of the gem # Default: true -w, [--workers=N] # Number of parallel workers to use when generating RBIs (default: auto) [--auto-strictness], [--no-auto-strictness], [--skip-auto-strictness] # Autocorrect strictness in gem RBIs in case of conflict with the DSL RBIs # Default: true --dsl-dir, [--dsl-dir=directory] # The DSL directory used to correct gems strictnesses ``` -------------------------------- ### ActiveResource::Base subclass example Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_activeresource.md An example of an ActiveResource::Base subclass with a defined schema. ```ruby class Post < ActiveResource::Base schema do integer 'id', 'month', 'year' end end ``` -------------------------------- ### Full Configuration Template Source: https://github.com/shopify/tapioca/blob/main/README.md The complete configuration file template with all options and their default values. ```yaml --- require: postrequire: sorbet/tapioca/require.rb todo: todo_file: sorbet/rbi/todo.rbi file_header: true dsl: outdir: sorbet/rbi/dsl file_header: true only: [] exclude: [] verify: false only_bootsnap_rbs_cache: false quiet: false workers: 1 rbi_max_line_length: 120 environment: development list_compilers: false app_root: "." halt_upon_load_error: true skip_constant: [] compiler_options: {} gem: outdir: sorbet/rbi/gems file_header: true all: false prerequire: '' postrequire: sorbet/tapioca/require.rb exclude: [] include_dependencies: false typed_overrides: activesupport: 'false' verify: false doc: true loc: true exported_gem_rbis: true workers: 1 auto_strictness: true dsl_dir: sorbet/rbi/dsl rbi_max_line_length: 120 environment: development halt_upon_load_error: true check_shims: gem_rbi_dir: sorbet/rbi/gems dsl_rbi_dir: sorbet/rbi/dsl shim_rbi_dir: sorbet/rbi/shims annotations_rbi_dir: sorbet/rbi/annotations todo_rbi_file: sorbet/rbi/todo.rbi payload: true workers: 1 annotations: sources: - https://raw.githubusercontent.com/Shopify/rbi-central/main netrc: true netrc_file: '' typed_overrides: {} ``` -------------------------------- ### Example Sidekiq Worker Class Source: https://github.com/shopify/tapioca/blob/main/manual/compiler_sidekiqworker.md An example of a Ruby class that includes the Sidekiq::Worker module. ```ruby class NotifierWorker include Sidekiq::Worker def perform(customer_id) # ... end end ``` -------------------------------- ### Help command for annotations Source: https://github.com/shopify/tapioca/blob/main/README.md Usage and options for the 'tapioca annotations' command. ```shell $ tapioca help annotations Usage: tapioca annotations Options: [--sources=one two three] # URIs of the sources to pull gem RBI annotations from # Default: "https://raw.githubusercontent.com/Shopify/rbi-central/main" [--netrc], [--no-netrc], [--skip-netrc] # Use .netrc to authenticate to private sources # Default: true [--netrc-file=NETRC_FILE] # Path to .netrc file [--auth=AUTH] # HTTP authorization header for private sources --typed, -t, [--typed-overrides=gem:level [gem:level ...]] # Override for typed sigils for pulled annotations -c, [--config=] # Path to the Tapioca configuration file # Default: sorbet/tapioca/config.yml -V, [--verbose], [--no-verbose], [--skip-verbose] # Verbose output for debugging purposes # Default: false Pull gem RBI annotations from remote sources ```