module FlydataCore module OptionValidator def self.included(base) base.extend(ClassMethods) end def validate_options(o, options = nil) self.class.validate_options(o, options) end module ClassMethods def validate_options(o, options = nil) if (options.nil?) unless defined?(self::OPTIONS) raise "validate_options needs OPTIONS hash defined" end options = self::OPTIONS end result = o.clone options.keys.each do |k| unless (result.has_key?(k)) if (options[k] != :mandatory) result[k] = options[k] else raise "Mandatory option #{k} is missing" end end end result end end end end