Sha256: 2956cc44df2744c437466a86a0a25897ff78fa11588b94ce13dd63ce31bb3e7c

Contents?: true

Size: 1.27 KB

Versions: 9

Compression:

Stored size: 1.27 KB

Contents

# typed: true
module Parlour
  # The RBI generator.
  class RbiGenerator < Generator
    # For backwards compatibility.
    # Before Parlour 5.0, Parlour::Options was Parlour::RbiGenerator::Options.
    Options = Parlour::Options

    def initialize(**hash)
      super
      @root = RbiGenerator::Namespace.new(self)
    end

    sig { overridable.returns(RbiGenerator::Namespace) }
    # The root {Namespace} of this generator.
    # @return [Namespace]
    attr_reader :root

    sig { overridable.params(strictness: String).returns(String) }
    # Returns the complete contents of the generated RBI file as a string.
    #
    # @return [String] The generated RBI file
    def rbi(strictness = 'strong')
      # TODO: Early test option - convert to RBS if requested
      # Absolutely remove this later on
      if ENV['PARLOUR_CONVERT_TO_RBS']
        # Perform conversion
        root.generalize_from_rbi!
        rbs_gen = Parlour::RbsGenerator.new
        converter = Parlour::Conversion::RbiToRbs.new(rbs_gen)
        root.children.each do |child|
          converter.convert_object(child, rbs_gen.root)
        end

        # Write the final RBS
        rbs_gen.rbs
      else
        "# typed: #{strictness}\n" + root.generate_rbi(0, options).join("\n") + "\n"
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
parlour-6.0.1 lib/parlour/rbi_generator.rb
parlour-6.0.0 lib/parlour/rbi_generator.rb
parlour-5.0.0 lib/parlour/rbi_generator.rb
parlour-5.0.0.beta.6 lib/parlour/rbi_generator.rb
parlour-5.0.0.beta.5 lib/parlour/rbi_generator.rb
parlour-5.0.0.beta.4 lib/parlour/rbi_generator.rb
parlour-5.0.0.beta.3 lib/parlour/rbi_generator.rb
parlour-5.0.0.beta.2 lib/parlour/rbi_generator.rb
parlour-5.0.0.beta.1 lib/parlour/rbi_generator.rb