Class: MCollective::Data::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/mcollective/data/result.rb

Instance Method Summary collapse

Constructor Details

#initialize(outputs) ⇒ Result

Returns a new instance of Result.



9
10
11
12
13
14
15
# File 'lib/mcollective/data/result.rb', line 9

def initialize(outputs)
  @data = {}

  outputs.keys.each do |output|
    @data[output] = Marshal.load(Marshal.dump(outputs[output].fetch(:default, nil)))
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Raises:

  • (NoMethodError)


36
37
38
39
40
41
42
# File 'lib/mcollective/data/result.rb', line 36

def method_missing(method, *args)
  key = method.to_sym

  raise NoMethodError, "undefined local variable or method `%s'" % key unless include?(key)

  @data[key]
end

Instance Method Details

#[](key) ⇒ Object



21
22
23
# File 'lib/mcollective/data/result.rb', line 21

def [](key)
  @data[key.to_sym]
end

#[]=(key, val) ⇒ Object



25
26
27
28
29
30
# File 'lib/mcollective/data/result.rb', line 25

def []=(key, val)
  # checks using the string representation of the class name to avoid deprecations on Bignum and Fixnum
  raise "Can only store String, Integer, Float or Boolean data but got #{val.class} for key #{key}" unless ["String", "Integer", "Bignum", "Fixnum", "Float", "TrueClass", "FalseClass"].include?(val.class.to_s)

  @data[key.to_sym] = val
end

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/mcollective/data/result.rb', line 17

def include?(key)
  @data.include?(key.to_sym)
end

#keysObject



32
33
34
# File 'lib/mcollective/data/result.rb', line 32

def keys
  @data.keys
end