Sha256: c7a6430f6c87fa33b452b9dab83898fefdf8fc99bcda2057031d409264e505d8

Contents?: true

Size: 1.63 KB

Versions: 3

Compression:

Stored size: 1.63 KB

Contents

require 'fileutils'

module Yoda
  module Store
    class Project
      require 'yoda/store/project/cache'
      require 'yoda/store/project/library_doc_loader'

      # @return [String]
      attr_reader :root_path

      # @return [Registry, nil]
      attr_reader :registry

      # @param root_path [String]
      def initialize(root_path)
        fail ArgumentError, root_path unless root_path.is_a?(String)

        @root_path = File.absolute_path(root_path)
      end

      def setup
        return if registry
        make_dir
        @registry = cache.prepare_registry
      end

      # Delete all data from registry
      def clear
        setup
        registry.clear
      end

      # @return [Array<BaseError>]
      def build_cache
        setup
        loader = LibraryDocLoader.build_for(self)
        loader.run
        load_project_files
        loader.errors
      end

      def rebuild_cache
        clear
        build_cache
      end

      def yoda_dir
        File.expand_path('.yoda', root_path)
      end

      # @param source_path [String]
      def read_source(source_path)
        Actions::ReadFile.run(registry, source_path)
      end

      private

      def load_project_files
        Logger.debug('Loading current project files...')
        Instrument.instance.initialization_progress(phase: :load_project_files, message: 'Loading current project files')
        Actions::ReadProjectFiles.new(registry, root_path).run
      end

      def make_dir
        File.exist?(yoda_dir) || FileUtils.mkdir(yoda_dir)
      end

      # @return [Cache]
      def cache
        @cache ||= Cache.build_for(self)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
yoda-language-server-0.7.2 lib/yoda/store/project.rb
yoda-language-server-0.7.1 lib/yoda/store/project.rb
yoda-language-server-0.7.0 lib/yoda/store/project.rb