Sha256: 9276c21ec095d73aef8f7f02c0b09d25dc7fd93eb7f1580cf69d1e04f0ec5a2e

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

# typed: true
require "rails"
require "sorbet-runtime"
require "sorbet-rails/config"

class SorbetRails::Railtie < Rails::Railtie
  railtie_name "sorbet-rails"

  rake_tasks do
    path = File.expand_path(T.must(__dir__))
    Dir.glob("#{path}/tasks/**/*.rake").each { |f| load f }
  end

  initializer "sorbet-rails.initialize" do
    ActiveSupport.on_load(:active_record) do
      require "sorbet-rails/rails_mixins/active_record_overrides"
      require "sorbet-rails/rails_mixins/custom_finder_methods"
      require "sorbet-rails/rails_mixins/pluck_to_tstruct"

      ActiveRecord::Base.extend SorbetRails::CustomFinderMethods
      ActiveRecord::Relation.include SorbetRails::CustomFinderMethods

      ActiveRecord::Base.extend SorbetRails::PluckToTStruct
      ActiveRecord::Relation.include SorbetRails::PluckToTStruct

      class ::ActiveRecord::Base
        # open ActiveRecord::Base to override inherited
        class << self
          alias_method :sbr_old_inherited, :inherited

          def inherited(child)
            sbr_old_inherited(child)
            # make the relation classes public so that they can be used for sorbet runtime checks
            child.send(:public_constant, :ActiveRecord_Relation)
            child.send(:public_constant, :ActiveRecord_AssociationRelation)
            child.send(:public_constant, :ActiveRecord_Associations_CollectionProxy)
          end
        end
      end
    end

    ActiveSupport.on_load(:action_controller) do
      require "sorbet-rails/rails_mixins/custom_params_methods"
      require "sorbet-rails/rails_mixins/generated_url_helpers"
      ActionController::Parameters.include SorbetRails::CustomParamsMethods
    end

    SorbetRails.register_configured_plugins
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sorbet-rails-0.6.0 lib/sorbet-rails/railtie.rb