Class: Rook::ValueTable
- Inherits:
-
Object
- Object
- Rook::ValueTable
- Defined in:
- lib/rook/kitchen.rb
Instance Method Summary collapse
- #evaluate_expr(expr, filename = '(expr)', linenum = 1) ⇒ Object
- #expand_value(value, filename = nil, linenum = nil) ⇒ Object
- #get_parameter(name) ⇒ Object
- #get_property(name) ⇒ Object
- #get_value(name) ⇒ Object
- #has_parameter?(name) ⇒ Boolean
- #has_property?(name) ⇒ Boolean
-
#initialize ⇒ ValueTable
constructor
A new instance of ValueTable.
- #parameter_names ⇒ Object
- #property_names ⇒ Object
- #set_parameter(name, value) ⇒ Object
- #set_property(name, value) ⇒ Object
Constructor Details
#initialize ⇒ ValueTable
Returns a new instance of ValueTable.
196 197 198 199 |
# File 'lib/rook/kitchen.rb', line 196 def initialize @_property_table = {} @_parameter_table = {} end |
Instance Method Details
#evaluate_expr(expr, filename = '(expr)', linenum = 1) ⇒ Object
267 268 269 270 271 |
# File 'lib/rook/kitchen.rb', line 267 def evaluate_expr(expr, filename='(expr)', linenum=1) code = @_parameter_table.keys.collect { |name| "#{name}=@_parameter_table['#{name}'];" } code << expr return self.instance_eval(code.join, filename.to_s, linenum) end |
#expand_value(value, filename = nil, linenum = nil) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/rook/kitchen.rb', line 240 def (value, filename=nil, linenum=nil) case value when String begin if value =~ /\A\$\(([a-zA-Z_]\w*)\)\z/ val = get_value($1) else val = value.gsub(/\$\(([a-zA-Z_]\w*)\)/) { get_value($1) } end rescue RookError => ex #ex.filename = filename #ex.linenum = linenum raise ex end when Array list = value.collect { |val| (val) } val = list when Hash hash = {} value.each { |key, val| hash[key] = (val) } val = hash else val = value end return val end |
#get_parameter(name) ⇒ Object
224 225 226 |
# File 'lib/rook/kitchen.rb', line 224 def get_parameter(name) return @_parameter_table[name.to_s] end |
#get_property(name) ⇒ Object
220 221 222 |
# File 'lib/rook/kitchen.rb', line 220 def get_property(name) return @_property_table[name.to_s] end |
#get_value(name) ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/rook/kitchen.rb', line 228 def get_value(name) name = name.to_s return get_property(name) if has_property?(name) # allow overwrite parameter by property return get_parameter(name) if has_parameter?(name) #if has_property?(name) || has_parameter?(name) # return _get(name) #end msg = "$(#{name}): no such property nor parameter." #raise UndefinedPropertyError.new(msg, name) raise RookError.new(msg) end |
#has_parameter?(name) ⇒ Boolean
205 206 207 |
# File 'lib/rook/kitchen.rb', line 205 def has_parameter?(name) return @_parameter_table.key?(name.to_s) end |
#has_property?(name) ⇒ Boolean
201 202 203 |
# File 'lib/rook/kitchen.rb', line 201 def has_property?(name) return @_property_table.key?(name.to_s) end |
#parameter_names ⇒ Object
277 278 279 |
# File 'lib/rook/kitchen.rb', line 277 def parameter_names return @_parameter_table.keys end |
#property_names ⇒ Object
273 274 275 |
# File 'lib/rook/kitchen.rb', line 273 def property_names return @_property_table.keys end |
#set_parameter(name, value) ⇒ Object
216 217 218 |
# File 'lib/rook/kitchen.rb', line 216 def set_parameter(name, value) @_parameter_table[name.to_s] = value end |
#set_property(name, value) ⇒ Object
209 210 211 212 213 214 |
# File 'lib/rook/kitchen.rb', line 209 def set_property(name, value) name = name.to_s return if has_property?(name) # cannot override @_property_table[name] = value instance_variable_set("@#{name}", value) end |