X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=lib%2Fmcollective%2Fdata%2Fresult.rb;fp=lib%2Fmcollective%2Fdata%2Fresult.rb;h=e19a652ffa8b10a6c21dacf1735b62acae39ee0f;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/lib/mcollective/data/result.rb b/lib/mcollective/data/result.rb new file mode 100644 index 0000000..e19a652 --- /dev/null +++ b/lib/mcollective/data/result.rb @@ -0,0 +1,40 @@ +module MCollective + module Data + class Result + # remove some methods that might clash with commonly + # used return data to improve the effectiveness of the + # method_missing lookup strategy + undef :type if method_defined?(:type) + + def initialize + @data = {} + end + + def include?(key) + @data.include?(key.to_sym) + end + + def [](key) + @data[key.to_sym] + end + + def []=(key, val) + raise "Can only store String, Integer, Float or Boolean data but got #{val.class} for key #{key}" unless [String, Fixnum, Bignum, Float, TrueClass, FalseClass].include?(val.class) + + @data[key.to_sym] = val + end + + def keys + @data.keys + end + + def method_missing(method, *args) + key = method.to_sym + + raise NoMethodError, "undefined local variable or method `%s'" % key unless include?(key) + + @data[key] + end + end + end +end