Class: NomNomNom::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/nom_nom_nom/status.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStatus

Returns a new instance of Status.



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/nom_nom_nom/status.rb', line 57

def initialize
  @cookbooks         = {}
  @updated_resources = {}
  @all_resources     = {}
  @start_time = nil
  @finish_time = nil
  @node = nil
  @recipes = []
  @roles   = []
  @exception = nil
  @backtrace = []
end

Instance Attribute Details

#all_resourcesObject (readonly)

Returns the value of attribute all_resources.



37
38
39
# File 'lib/nom_nom_nom/status.rb', line 37

def all_resources
  @all_resources
end

#backtraceObject (readonly)

Returns the value of attribute backtrace.



55
56
57
# File 'lib/nom_nom_nom/status.rb', line 55

def backtrace
  @backtrace
end

#cookbooksObject (readonly)

Returns the value of attribute cookbooks.



45
46
47
# File 'lib/nom_nom_nom/status.rb', line 45

def cookbooks
  @cookbooks
end

#exceptionObject (readonly)

Returns the value of attribute exception.



53
54
55
# File 'lib/nom_nom_nom/status.rb', line 53

def exception
  @exception
end

#finish_timeObject (readonly)

Returns the value of attribute finish_time.



43
44
45
# File 'lib/nom_nom_nom/status.rb', line 43

def finish_time
  @finish_time
end

#nodeObject (readonly)

Returns the value of attribute node.



47
48
49
# File 'lib/nom_nom_nom/status.rb', line 47

def node
  @node
end

#recipesObject (readonly)

Returns the value of attribute recipes.



49
50
51
# File 'lib/nom_nom_nom/status.rb', line 49

def recipes
  @recipes
end

#rolesObject (readonly)

Returns the value of attribute roles.



51
52
53
# File 'lib/nom_nom_nom/status.rb', line 51

def roles
  @roles
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



41
42
43
# File 'lib/nom_nom_nom/status.rb', line 41

def start_time
  @start_time
end

#updated_resourcesObject (readonly)

Returns the value of attribute updated_resources.



39
40
41
# File 'lib/nom_nom_nom/status.rb', line 39

def updated_resources
  @updated_resources
end

Class Method Details

.from_hash(status_hash) ⇒ Object



31
32
33
34
35
# File 'lib/nom_nom_nom/status.rb', line 31

def self.from_hash(status_hash)
  s = new
  s.consume_hash(status_hash)
  s
end

.from_run_status(run_status) ⇒ Object

create a Status from a Chef::RunStatus



25
26
27
28
29
# File 'lib/nom_nom_nom/status.rb', line 25

def self.from_run_status(run_status)
  s = new
  s.consume_run_status(run_status)
  s
end

Instance Method Details

#==(other) ⇒ Object



116
117
118
# File 'lib/nom_nom_nom/status.rb', line 116

def ==(other)
  other.kind_of?(NomNomNom::Status) && other.to_hash == to_hash
end

#consume_hash(hash) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/nom_nom_nom/status.rb', line 94

def consume_hash(hash)
  hash = stringify_hash_keys(hash)

  @all_resources     = hash['all_resources']
  @updated_resources = hash['updated_resources']
  @start_time        = hash['start_time']
  @finish_time       = hash['finish_time']
  @cookbooks         = hash['cookbooks']
  @node              = hash['node']
  @recipes           = hash['recipes']
  @roles             = hash['roles']

  @exception         = hash["exception"]
  @backtrace         = hash["exception_backtrace"]

  self
end

#consume_run_status(run_status) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/nom_nom_nom/status.rb', line 70

def consume_run_status(run_status)
  extract_resources(run_status)
  extract_timing(run_status)
  extract_cookbook_names_and_versions(run_status)
  extract_node_info(run_status)
  extract_exception(run_status)
end

#success?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/nom_nom_nom/status.rb', line 112

def success?
  !@exception
end

#to_hashObject Also known as: for_json



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/nom_nom_nom/status.rb', line 78

def to_hash
  { :all_resources     => all_resources,
    :updated_resources => updated_resources,
    :start_time        => start_time,
    :finish_time       => finish_time,
    :cookbooks         => cookbooks,
    :node              => node,
    :recipes           => recipes,
    :roles             => roles,
    :success           => success?,
    :exception         => (exception),
    :exception_backtrace => backtrace }
end