Sha256: d9a3266826892cb0a4c49ba1dd27a7aa72a72d3e75b7d3fcd161c43a7f276f0f

Contents?: true

Size: 1.04 KB

Versions: 30

Compression:

Stored size: 1.04 KB

Contents

# typed: strict
# frozen_string_literal: true

module Tapioca
  module Gem
    module Listeners
      class SorbetProps < Base
        extend T::Sig

        private

        sig { override.params(event: ScopeNodeAdded).void }
        def on_scope(event)
          constant = event.constant
          node = event.node

          return unless T::Props::ClassMethods === constant

          constant.props.map do |name, prop|
            type = prop.fetch(:type_object, "T.untyped").to_s.gsub(".returns(<VOID>)", ".void")

            default = prop.key?(:default) || prop.key?(:factory) ? "T.unsafe(nil)" : nil
            node << if prop.fetch(:immutable, false)
              RBI::TStructConst.new(name.to_s, type, default: default)
            else
              RBI::TStructProp.new(name.to_s, type, default: default)
            end
          end
        end

        sig { override.params(event: NodeAdded).returns(T::Boolean) }
        def ignore?(event)
          event.is_a?(Tapioca::Gem::ForeignScopeNodeAdded)
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
tapioca-0.11.17 lib/tapioca/gem/listeners/sorbet_props.rb
tapioca-0.11.16 lib/tapioca/gem/listeners/sorbet_props.rb
tapioca-0.11.15 lib/tapioca/gem/listeners/sorbet_props.rb
tapioca-0.11.14 lib/tapioca/gem/listeners/sorbet_props.rb
tapioca-0.11.13 lib/tapioca/gem/listeners/sorbet_props.rb
tapioca-0.11.12 lib/tapioca/gem/listeners/sorbet_props.rb
tapioca-0.11.11 lib/tapioca/gem/listeners/sorbet_props.rb
tapioca-0.11.10 lib/tapioca/gem/listeners/sorbet_props.rb
tapioca-0.11.9 lib/tapioca/gem/listeners/sorbet_props.rb
tapioca-0.11.8 lib/tapioca/gem/listeners/sorbet_props.rb
tapioca-0.11.7 lib/tapioca/gem/listeners/sorbet_props.rb
tapioca-0.11.6 lib/tapioca/gem/listeners/sorbet_props.rb
tapioca-0.11.5 lib/tapioca/gem/listeners/sorbet_props.rb
tapioca-0.11.4 lib/tapioca/gem/listeners/sorbet_props.rb
tapioca-0.11.3 lib/tapioca/gem/listeners/sorbet_props.rb
tapioca-0.11.2 lib/tapioca/gem/listeners/sorbet_props.rb
devcycle-ruby-server-sdk-2.0.0 vendor/bundle/ruby/3.0.0/gems/tapioca-0.11.1/lib/tapioca/gem/listeners/sorbet_props.rb
tapioca-0.11.1 lib/tapioca/gem/listeners/sorbet_props.rb
tapioca-0.11.0 lib/tapioca/gem/listeners/sorbet_props.rb
tapioca-0.10.5 lib/tapioca/gem/listeners/sorbet_props.rb