Sha256: 18aaf3315d26cccb9b77425d526531af17cf50cf6438fc5784b6bf2902cb1267

Contents?: true

Size: 1.03 KB

Versions: 26

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require "json"

module SublimeTextKit
  # Manages Sublime Text session data.
  class Session
    attr_reader :metadata_dir

    def self.home_path
      ENV.fetch "HOME"
    end

    def self.session_path
      "#{home_path}/Library/Application Support/Sublime Text 3/Local/Session.sublime_session"
    end

    def initialize metadata_directory
      @metadata_dir = File.expand_path metadata_directory
    end

    def workspaces
      Dir["#{metadata_dir}/*.sublime-workspace"].sort
    end

    def rebuild_recent_workspaces
      session = load_session
      return unless session && session["workspaces"] && session["workspaces"]["recent_workspaces"]

      session["workspaces"]["recent_workspaces"] = workspaces
      save_session session
    end

    private

    def load_session
      File.exist?(self.class.session_path) ? JSON.parse(File.read(self.class.session_path)) : {}
    end

    def save_session json
      File.open(self.class.session_path, "w") { |file| file.write JSON.dump(json) }
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
sublime_text_kit-10.0.0 lib/sublime_text_kit/session.rb
sublime_text_kit-9.6.0 lib/sublime_text_kit/session.rb
sublime_text_kit-9.5.0 lib/sublime_text_kit/session.rb
sublime_text_kit-9.4.0 lib/sublime_text_kit/session.rb
sublime_text_kit-9.3.0 lib/sublime_text_kit/session.rb
sublime_text_kit-9.2.0 lib/sublime_text_kit/session.rb
sublime_text_kit-9.1.0 lib/sublime_text_kit/session.rb
sublime_text_kit-9.0.0 lib/sublime_text_kit/session.rb
sublime_text_kit-8.5.2 lib/sublime_text_kit/session.rb
sublime_text_kit-8.5.1 lib/sublime_text_kit/session.rb
sublime_text_kit-8.5.0 lib/sublime_text_kit/session.rb
sublime_text_kit-8.4.0 lib/sublime_text_kit/session.rb
sublime_text_kit-8.3.0 lib/sublime_text_kit/session.rb
sublime_text_kit-8.2.0 lib/sublime_text_kit/session.rb
sublime_text_kit-8.1.0 lib/sublime_text_kit/session.rb
sublime_text_kit-8.0.0 lib/sublime_text_kit/session.rb
sublime_text_kit-7.2.0 lib/sublime_text_kit/session.rb
sublime_text_kit-7.1.0 lib/sublime_text_kit/session.rb
sublime_text_kit-7.0.0 lib/sublime_text_kit/session.rb
sublime_text_kit-6.2.1 lib/sublime_text_kit/session.rb