Class: Quay::State

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

Instance Method Summary collapse

Constructor Details

#initialize(file = ".quay.yml") ⇒ State

Returns a new instance of State.



3
4
5
# File 'lib/quay/state.rb', line 3

def initialize(file = ".quay.yml")
  @file = file
end

Instance Method Details

#_loadObject



32
33
34
35
36
37
38
39
40
# File 'lib/quay/state.rb', line 32

def _load
  if File.exists?(@file)
    @state = YAML.load_file(@file)
  else
    @state = {}
  end
  @state.default_proc = proc { |hash, key| hash[key] = {} }
  @state
end

#_saveObject



26
27
28
29
30
# File 'lib/quay/state.rb', line 26

def _save
  File.open(@file, "w") do |file|
    YAML.dump(@state, file)
  end
end

#_stateObject



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

def _state
  _load if @state.nil?
  @state
end

#containersObject



7
8
9
# File 'lib/quay/state.rb', line 7

def containers
  _state["containers"]
end

#remove_container(name) ⇒ Object



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

def remove_container(name)
  containers.delete(name)
  _save
end

#save_container(name, id) ⇒ Object



11
12
13
14
# File 'lib/quay/state.rb', line 11

def save_container(name, id)
  containers[name] = id
  _save
end