Sha256: 9dbf8bdb40fb65a984e2447ba345a76834a43fda0019fad34e63071a7da4ced3

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

require "multi_json"

module SublimeTextKit
  class Session
    attr_reader :workspace_dir

    def self.home_path
      ENV.fetch "HOME"
    end

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

    def initialize options = {}
      @workspace_dir = File.expand_path options.fetch(:workspace_dir)
    end

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

    def rebuild_recent_workspaces
      session = load_session

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

    private

    def load_session
      File.exists?(self.class.session_path) ? MultiJson.load(File.read(self.class.session_path)) : {}
    end

    def save_session json
      File.open(self.class.session_path, 'w') { |file| file.write MultiJson.dump(json, pretty: true) }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sublime_text_kit-2.0.0 lib/sublime_text_kit/session.rb
sublime_text_kit-1.1.1 lib/sublime_text_kit/session.rb
sublime_text_kit-1.1.0 lib/sublime_text_kit/session.rb
sublime_text_kit-1.0.0 lib/sublime_text_kit/session.rb