Sha256: c51cae639654ed7398e307e96848a3e71fae3c1c9c15f4f796123247334baffa

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

module Steep
  class Project
    class SignatureFile
      attr_reader :path
      attr_reader :content
      attr_reader :content_updated_at

      ParseErrorStatus = Struct.new(:error, :timestamp, keyword_init: true)
      DeclarationsStatus = Struct.new(:declarations, :timestamp, keyword_init: true)

      def initialize(path:)
        @path = path
        self.content = ""
      end

      def content=(content)
        @content_updated_at = Time.now
        @content = content
        @status = nil
      end

      def status
        unless @status
          @status = DeclarationsStatus.new(declarations: [], timestamp: Time.now)
        end

        @status
      end

      def load!
        buffer = RBS::Buffer.new(name: path, content: content)
        decls = RBS::Parser.parse_signature(buffer)
        @status = DeclarationsStatus.new(declarations: decls, timestamp: Time.now)
      rescue RBS::Parser::SyntaxError, RBS::Parser::SemanticsError => exn
        @status = ParseErrorStatus.new(error: exn, timestamp: Time.now)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
steep-0.41.0 lib/steep/project/signature_file.rb
steep-0.40.0 lib/steep/project/signature_file.rb