Method: CfYAML.process

Defined in:
lib/libcfruby/cfyaml.rb

.process(object, changed = false) ⇒ Object

Executes an object loaded from a YAML file. changed is only used internally. Returns true if a known change was made. Specifically, it does the following (in order):

1. Check for a +condition+ key.  If it exists, eval it as a ruby statement and stop processing if the
   result of the eval() is false or nil.
2. Check for a +change_made+ key (which must be set to true or false).  This value is checked against
  whether or not a change was actually made by the *immediately previous* section.  If they do not match, then
  this section will stop processing.
3. The section is searched for a primary key, which will then determine how the rest of the section is
  processed.  These are:
   * load
   * actions
   * eval
   * filename
   * install
   * delete
   * disable
   * execute


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/libcfruby/cfyaml.rb', line 79

def CfYAML.process(object, changed=false)
	if(object.kind_of?(Hash))
		begin
			# first check for condition
			if(object.has_key?('conditions'))
				conditions = object['conditions']
				if(!conditions.kind_of?(Array))
					conditions = Array.[](conditions)
				end
		
				conditions.each() { |c|
					if(!eval(c.to_s))
						return(false)
					end
				}
			end
			
			if(object.has_key?('change_made'))
				if(object['change_made'] != changed)
					return(false)
				end
			end

			# load has to be handled here because it should not change
			# the changed flag on its own.
			if(object.has_key?('load'))
				if(object['load'].kind_of?(Array))
					object['load'].each() { |s|
						changed = load(s, changed)
					}
				else
					changed = load(object['load'], changed)
				end
			end

			changed = false
	
			if(object.has_key?('actions'))
				changed = process(object['actions'], changed)
			elsif(object.has_key?('eval'))
				evaluate(object)
			elsif(object.has_key?('filename'))
				changed = configure_file(object)
			elsif(object.has_key?('install'))
				changed = install_packages(object)
			elsif(object.has_key?('delete'))
				changed = delete(object)
			elsif(object.has_key?('disable'))
				changed = disable(object)
			elsif(object.has_key?('execute'))
				execute(object)
			else
				raise(CfYamlError, "Unable to find primary key (actions, eval, filename, install, or execute)")
			end
		rescue
			raise(CfYamlError, "Error processing section:\n #{object.to_yaml}\n\n#{$!.to_s}\n\n")
		end
	elsif(object.kind_of?(Array))
		object.each() { |o|
			changed = process(o, changed)
		}
	end
	
	return(changed)
end