module Leeroy::Helpers::State

Attributes

state[RW]

Public Instance Methods

dump_state() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/leeroy/helpers/state.rb, line 38
def rotate_task_metadata
  logger.debug "rotating task metadata"
  if self.state.metadata.task?
    self.state.metadata.previous = self.state.metadata.task
  end
  self.state.metadata.task = self.class.to_s
end
state_from_pipe(state = {}, global_options = self.global_options) click to toggle source
# 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_s() click to toggle source
# File lib/leeroy/helpers/state.rb, line 46
def to_s
  "#{self.metadata},#{self.data}"
end

Private Instance Methods

_stdin?() click to toggle source

this is preposterous BS and doubtless not portable to Windows

# File lib/leeroy/helpers/state.rb, line 53
def _stdin?
  $stdin.fcntl(Fcntl::F_GETFL, 0) == 0
end