Module: Leeroy::Helpers::State
- Includes:
- Leeroy::Helpers
- Included in:
- State, Task, Task::Base
- Defined in:
- lib/leeroy/helpers/state.rb
Instance Attribute Summary collapse
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #dump_state ⇒ Object
- #load_state ⇒ Object
- #rotate_task_metadata ⇒ Object
- #state_from_pipe(state = {}, global_options = self.global_options) ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#state ⇒ Object
Returns the value of attribute state.
11 12 13 |
# File 'lib/leeroy/helpers/state.rb', line 11 def state @state end |
Instance Method Details
#dump_state ⇒ Object
33 34 35 36 |
# File 'lib/leeroy/helpers/state.rb', line 33 def dump_state logger.debug "dumping state to stdout" $stdout.puts self.state.dump end |
#load_state ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/leeroy/helpers/state.rb', line 22 def load_state begin logger.debug "loading state from stdin if available" _stdin? ? MultiJson.load($stdin.read, :symbolize_keys => true) : {} rescue StandardError => e raise e end end |
#rotate_task_metadata ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/leeroy/helpers/state.rb', line 38 def logger.debug "rotating task metadata" if self.state..task? self.state..previous = self.state..task end self.state..task = self.class.to_s end |
#state_from_pipe(state = {}, global_options = self.global_options) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/leeroy/helpers/state.rb', line 13 def state_from_pipe(state = {}, = self.) begin state.merge(load_state) rescue StandardError => e raise e end end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/leeroy/helpers/state.rb', line 46 def to_s "#{self.},#{self.data}" end |