Sha256: 6db7265317ccf356190b7c712b99c2188cea734c9de15cd1796d6b1fc607c463

Contents?: true

Size: 981 Bytes

Versions: 8

Compression:

Stored size: 981 Bytes

Contents

# frozen_string_literal: true

require "json"
require "refinements/pathname"

module SublimeTextKit
  module Sessions
    # Manages the rebuilding of session information.
    class Rebuilder
      include Import[:settings]

      using Refinements::Pathname

      def call
        session = read

        return unless session.dig "workspaces", "recent_workspaces"

        Pathname(metadata_dir).expand_path
                              .files("*.sublime-workspace")
                              .then do |workspaces|
                                session["workspaces"]["recent_workspaces"] = workspaces
                                write session
                              end
      end

      private

      def read = source_path.exist? ? JSON(source_path.read) : {}

      def write(json) = JSON.dump(json).then { |content| source_path.write content }

      def metadata_dir = settings.metadata_dir

      def source_path = settings.session_path
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sublime_text_kit-17.6.0 lib/sublime_text_kit/sessions/rebuilder.rb
sublime_text_kit-17.5.0 lib/sublime_text_kit/sessions/rebuilder.rb
sublime_text_kit-17.4.0 lib/sublime_text_kit/sessions/rebuilder.rb
sublime_text_kit-17.3.0 lib/sublime_text_kit/sessions/rebuilder.rb
sublime_text_kit-17.2.0 lib/sublime_text_kit/sessions/rebuilder.rb
sublime_text_kit-17.1.0 lib/sublime_text_kit/sessions/rebuilder.rb
sublime_text_kit-17.0.1 lib/sublime_text_kit/sessions/rebuilder.rb
sublime_text_kit-17.0.0 lib/sublime_text_kit/sessions/rebuilder.rb