Class: Leeroy::State

Inherits:
Types::Dash show all
Includes:
Helpers::Dumpable, Helpers::Logging, Helpers::Polling, Helpers::State
Defined in:
lib/leeroy/state.rb

Constant Summary

Constants included from Helpers::Polling

Helpers::Polling::POLL_CALLBACK, Helpers::Polling::POLL_INTERVAL, Helpers::Polling::POLL_TIMEOUT

Constants included from Helpers::Logging

Helpers::Logging::TRACE_FORMAT, Helpers::Logging::TRACE_LEVELS, Helpers::Logging::TRUNCATE_THRESHOLD

Instance Attribute Summary

Attributes included from Helpers::State

#state

Attributes included from Helpers::Polling

#poll_callback, #poll_interval, #poll_response, #poll_timeout

Attributes included from Helpers::Env

#env

Attributes included from Helpers::Dumpable

#dump_properties

Instance Method Summary collapse

Methods included from Helpers::State

#dump_state, #load_state, #rotate_task_metadata, #state_from_pipe, #to_s

Methods included from Helpers::Polling

#poll

Methods included from Helpers::Env

#checkEnv

Methods included from Helpers::Logging

#logger

Methods included from Helpers::Dumpable

#dump, #dumper

Methods inherited from Types::Dash

#dumper

Constructor Details

#initialize(*args, &block) ⇒ State

Returns a new instance of State.



60
61
62
63
64
65
66
67
# File 'lib/leeroy/state.rb', line 60

def initialize(*args, &block)
  super

  self.dump_properties = [
    :data,
    :metadata,
  ]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/leeroy/state.rb', line 43

def method_missing(method, *args, &block)
  begin
    self.data.send(method.to_sym, *args, &block)

  rescue NoMethodError => e
    logger.debug e.message
    if self.respond_to?(method.to_sym)
      self.send(method.to_sym, *args, &block)
    else
      raise e
    end

  rescue StandardError => e
    raise e
  end
end

Instance Method Details

#fetch(*args, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/leeroy/state.rb', line 19

def fetch(*args, &block)
  begin
    self.data.send(:fetch, *args, &block)

  rescue KeyError => e
    logger.debug e.message

    not_found = args[0]
    logger.debug "property '#{not_found}' not found in statedata, checking state"

    begin
      self.send(not_found.to_sym, &block)

    rescue KeyError => e
      logger.debug e.message

      logger.warn "property '#{not_found}' not found in statedata or state"
    end

  rescue StandardError => e
    raise e
  end
end