Class: Kozo::State
- Inherits:
-
Object
- Object
- Kozo::State
- Defined in:
- lib/kozo/state.rb
Constant Summary collapse
- VERSION =
2
Instance Attribute Summary collapse
-
#resources ⇒ Object
Returns the value of attribute resources.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #compatible? ⇒ Boolean
-
#initialize(resources = [], version = VERSION, verify: true) ⇒ State
constructor
A new instance of State.
- #to_h ⇒ Object
Constructor Details
#initialize(resources = [], version = VERSION, verify: true) ⇒ State
Returns a new instance of State.
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
#resources ⇒ Object
Returns the value of attribute resources.
7 8 9 |
# File 'lib/kozo/state.rb', line 7 def resources @resources end |
#version ⇒ Object
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
16 17 18 |
# File 'lib/kozo/state.rb', line 16 def compatible? version == State::VERSION end |
#to_h ⇒ Object
24 25 26 27 28 29 |
# File 'lib/kozo/state.rb', line 24 def to_h { version: VERSION, resources: resources.map(&:to_h), } end |