Class: Kozo::State

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

Constant Summary collapse

VERSION =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resources = [], version = VERSION, verify: true) ⇒ State

Returns a new instance of State.

Raises:



9
10
11
12
13
14
# File 'lib/kozo/state.rb', line 9

def initialize(resources = [], version = VERSION, verify: true)
  @resources = Array(resources)
  @version = version

  raise StateError, "unexpected version in state: got #{version}, expected #{State::VERSION}\nRun `#{File.basename($PROGRAM_NAME)} state upgrade` to upgrade your state file" unless compatible? || !verify
end

Instance Attribute Details

#resourcesObject

Returns the value of attribute resources.



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

def resources
  @resources
end

#versionObject

Returns the value of attribute version.



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

def version
  @version
end

Instance Method Details

#==(other) ⇒ Object



20
21
22
# File 'lib/kozo/state.rb', line 20

def ==(other)
  resources == other.resources
end

#compatible?Boolean

Returns:

  • (Boolean)


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

def compatible?
  version == State::VERSION
end

#to_hObject



24
25
26
27
28
29
# File 'lib/kozo/state.rb', line 24

def to_h
  {
    version: VERSION,
    resources: resources.map(&:to_h),
  }
end