Skip to content

Latest commit

 

History

History
57 lines (44 loc) · 1.05 KB

compiler_actioncontrollerhelpers.md

File metadata and controls

57 lines (44 loc) · 1.05 KB

ActionControllerHelpers

Tapioca::Dsl::Compilers::ActionControllerHelpers decorates RBI files for all subclasses of ActionController::Base.

For example, with the following MyHelper module:

module MyHelper
  def greet(user)
    # ...
  end

 def localized_time
    # ...
  end
end

and the following controller:

class UserController < ActionController::Base
  helper MyHelper
  helper { def age(user) "99" end }
  helper_method :current_user_name

  def current_user_name
    # ...
  end
end

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

# user_controller.rbi
# typed: strong
class UserController
  module HelperMethods
    include MyHelper

    sig { params(user: T.untyped).returns(T.untyped) }
    def age(user); end

    sig { returns(T.untyped) }
    def current_user_name; end
  end

  class HelperProxy < ::ActionView::Base
    include HelperMethods
  end

  sig { returns(HelperProxy) }
  def helpers; end
end