Sha256: bc8c45fec45c99d31d23a96aaf869aa5561dd6fdd654be20955cc94d4ef8985a

Contents?: true

Size: 970 Bytes

Versions: 1

Compression:

Stored size: 970 Bytes

Contents

require "oj"

module SublimeTextKit
  class Session
    attr_accessor :workspaces_path

    def self.home_path
      ENV["HOME"]
    end

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

    def initialize workspaces_path: ''
      @workspaces_path = workspaces_path
    end

    def workspaces
      Dir["#{workspaces_path}/*.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) ? Oj.load(File.read(self.class.session_path)) : {}
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sublime_text_kit-0.1.0 lib/sublime_text_kit/session.rb