Sha256: 5536aceffcdbf9d29c0c61291de0b23091c51eb2760c8f787e8e9af3079a8e8a

Contents?: true

Size: 1.47 KB

Versions: 48

Compression:

Stored size: 1.47 KB

Contents

# typed: strict
# frozen_string_literal: true

module Tapioca
  module Gem
    module Listeners
      class Base
        extend T::Sig
        extend T::Helpers

        abstract!

        sig { params(pipeline: Pipeline).void }
        def initialize(pipeline)
          @pipeline = pipeline
        end

        sig { params(event: NodeAdded).void }
        def dispatch(event)
          return if ignore?(event)

          case event
          when ConstNodeAdded
            on_const(event)
          when ScopeNodeAdded
            on_scope(event)
          when MethodNodeAdded
            on_method(event)
          else
            raise "Unsupported event #{event.class}"
          end
        end

        private

        sig { params(event: ConstNodeAdded).void }
        def on_const(event)
        end

        sig { params(event: ScopeNodeAdded).void }
        def on_scope(event)
        end

        sig { params(event: MethodNodeAdded).void }
        def on_method(event)
        end

        sig { params(event: NodeAdded).returns(T::Boolean) }
        def ignore?(event)
          # Some listeners do not have to take any action on certain events. For example,
          # almost every listener should skip ForeignScopeNodeAdded events in order not to generate
          # unnecessary RBIs for foreign constants. This method should be overridden by listener
          # subclasses to skip any events that aren't relevant to them.
          false
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
tapioca-0.16.8 lib/tapioca/gem/listeners/base.rb
tapioca-0.16.7 lib/tapioca/gem/listeners/base.rb
tapioca-0.16.6 lib/tapioca/gem/listeners/base.rb
tapioca-0.16.5 lib/tapioca/gem/listeners/base.rb
tapioca-0.16.4 lib/tapioca/gem/listeners/base.rb
tapioca-0.16.3 lib/tapioca/gem/listeners/base.rb
tapioca-0.16.2 lib/tapioca/gem/listeners/base.rb
tapioca-0.16.1 lib/tapioca/gem/listeners/base.rb
tapioca-0.16.0 lib/tapioca/gem/listeners/base.rb
tapioca-0.15.1 lib/tapioca/gem/listeners/base.rb
tapioca-0.15.0 lib/tapioca/gem/listeners/base.rb
tapioca-0.14.4 lib/tapioca/gem/listeners/base.rb
tapioca-0.14.3 lib/tapioca/gem/listeners/base.rb
tapioca-0.13.3 lib/tapioca/gem/listeners/base.rb
tapioca-0.13.2 lib/tapioca/gem/listeners/base.rb
tapioca-0.13.1 lib/tapioca/gem/listeners/base.rb
tapioca-0.13.0 lib/tapioca/gem/listeners/base.rb
tapioca-0.12.0 lib/tapioca/gem/listeners/base.rb
tapioca-0.11.17 lib/tapioca/gem/listeners/base.rb
tapioca-0.11.16 lib/tapioca/gem/listeners/base.rb