# File lib/templater/description.rb, line 47 47: def extract(argument) 48: case options[:as] 49: when :hash 50: if argument.is_a?(String) 51: return argument.split(',').inject({}) do |h, pair| 52: key, value = pair.strip.split(':') 53: raise Templater::MalformattedArgumentError, "Expected '#{argument.inspect}' to be a key/value pair" unless key and value 54: h[key] = value 55: h 56: end 57: end 58: when :array 59: return argument.split(',') if argument.is_a?(String) 60: end 61: return argument 62: end
Checks if the given argument is valid according to this description
argument | Checks if the given argument is valid. |
Boolean | Validity of the argument |
# File lib/templater/description.rb, line 29 29: def valid?(argument) 30: if argument.nil? and options[:required] 31: raise Templater::TooFewArgumentsError 32: elsif not argument.nil? 33: if options[:as] == :hash and not argument.is_a?(Hash) 34: raise Templater::MalformattedArgumentError, "Expected the argument to be a Hash, but was '#{argument.inspect}'" 35: elsif options[:as] == :array and not argument.is_a?(Array) 36: raise Templater::MalformattedArgumentError, "Expected the argument to be an Array, but was '#{argument.inspect}'" 37: end 38: 39: invalid = catch :invalid do 40: block.call(argument) if block 41: throw :invalid, :not_invalid 42: end 43: raise Templater::ArgumentError, invalid unless invalid == :not_invalid 44: end 45: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.