Class: Yildun::SessionState

Inherits:
Object
  • Object
show all
Defined in:
lib/yildun/session.rb,
sig/yildun.rbs

Class Method Summary collapse

Class Method Details

.load(path) ⇒ Array[Hash[String, untyped]]

Parameters:

  • path (String)

Returns:

  • (Array[Hash[String, untyped]])


13
14
15
16
17
18
# File 'lib/yildun/session.rb', line 13

def self.load(path)
  return [] unless File.file?(path)
  JSON.parse(File.read(path)).fetch("tabs", [])
rescue JSON::ParserError
  []
end

.save(path, tabs:) ⇒ Object

Parameters:

  • path (String)
  • tabs: (Array[untyped])

Returns:

  • (Object)


8
9
10
11
# File 'lib/yildun/session.rb', line 8

def self.save(path, tabs:)
  FileUtils.mkdir_p(File.dirname(path))
  File.write(path, JSON.pretty_generate("tabs" => tabs.map { |tab| {"title" => tab.title, "cwd" => tab.terminal.cwd} }))
end