Sha256: f64ee19f332994d43bf5368707ceb81840faed5faace3a26d3cd6e4fff2a8add

Contents?: true

Size: 1.46 KB

Versions: 15

Compression:

Stored size: 1.46 KB

Contents

# typed: strict
# frozen_string_literal: true

module RBI
  module Rewriters
    class NestNonPublicMethods < Visitor
      extend T::Sig

      sig { override.params(node: T.nilable(Node)).void }
      def visit(node)
        return unless node

        case node
        when Tree
          public_group = VisibilityGroup.new(Public.new)
          protected_group = VisibilityGroup.new(Protected.new)
          private_group = VisibilityGroup.new(Private.new)

          node.nodes.dup.each do |child|
            visit(child)
            next unless child.is_a?(Method)
            child.detach
            case child.visibility
            when Protected
              protected_group << child
            when Private
              private_group << child
            else
              public_group << child
            end
          end

          node << public_group unless public_group.empty?
          node << protected_group unless protected_group.empty?
          node << private_group unless private_group.empty?
        end
      end
    end
  end

  class Tree
    extend T::Sig

    sig { void }
    def nest_non_public_methods!
      visitor = Rewriters::NestNonPublicMethods.new
      visitor.visit(self)
    end
  end

  class VisibilityGroup < Tree
    extend T::Sig

    sig { returns(Visibility) }
    attr_reader :visibility

    sig { params(visibility: Visibility).void }
    def initialize(visibility)
      super()
      @visibility = visibility
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
devcycle-ruby-server-sdk-2.0.0 vendor/bundle/ruby/3.0.0/gems/rbi-0.0.16/lib/rbi/rewriters/nest_non_public_methods.rb
rbi-0.0.16 lib/rbi/rewriters/nest_non_public_methods.rb
rbi-0.0.15 lib/rbi/rewriters/nest_non_public_methods.rb
rbi-0.0.14 lib/rbi/rewriters/nest_non_public_methods.rb
rbi-0.0.13 lib/rbi/rewriters/nest_non_public_methods.rb
rbi-0.0.12 lib/rbi/rewriters/nest_non_public_methods.rb
rbi-0.0.11 lib/rbi/rewriters/nest_non_public_methods.rb
rbi-0.0.10 lib/rbi/rewriters/nest_non_public_methods.rb
rbi-0.0.9 lib/rbi/rewriters/nest_non_public_methods.rb
rbi-0.0.8 lib/rbi/rewriters/nest_non_public_methods.rb
rbi-0.0.7 lib/rbi/rewriters/nest_non_public_methods.rb
rbi-0.0.6 lib/rbi/rewriters/nest_non_public_methods.rb
rbi-0.0.5 lib/rbi/rewriters/nest_non_public_methods.rb
rbi-0.0.4 lib/rbi/rewriters/nest_non_public_methods.rb
rbi-0.0.3 lib/rbi/rewriters/nest_non_public_methods.rb