Module: Leeroy::Helpers::State

Includes:
Leeroy::Helpers
Included in:
State, Task, Task::Base
Defined in:
lib/leeroy/helpers/state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#stateObject

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_stateObject



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_stateObject



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_metadataObject



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 = {}, global_options = self.global_options)
  begin
    state.merge(load_state)

  rescue StandardError => e
    raise e
  end
end

#to_sObject



46
47
48
# File 'lib/leeroy/helpers/state.rb', line 46

def to_s
  "#{self.},#{self.data}"
end