Class: GT::State

Inherits:
Object
  • Object
show all
Defined in:
lib/gt/state.rb

Constant Summary collapse

FILE_NAME =
"gt-restack-state"

Instance Method Summary collapse

Constructor Details

#initializeState

Returns a new instance of State.



9
10
11
# File 'lib/gt/state.rb', line 9

def initialize
  @path = File.join(GT::Git.git_dir, FILE_NAME)
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/gt/state.rb', line 13

def active?
  File.exist?(@path)
end

#clearObject



27
28
29
# File 'lib/gt/state.rb', line 27

def clear
  File.delete(@path) if active?
end

#loadObject



21
22
23
24
25
# File 'lib/gt/state.rb', line 21

def load
  return nil unless active?

  JSON.parse(File.read(@path), symbolize_names: true)
end

#save(data) ⇒ Object



17
18
19
# File 'lib/gt/state.rb', line 17

def save(data)
  File.write(@path, JSON.generate(data))
end