1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
module Validatable
module Understandable #:nodoc:
module ClassMethods #:nodoc:
def understands(*args)
understandings.concat args
end
def understandings
@understandings ||= []
end
def all_understandings
return understandings + self.superclass.all_understandings if self.superclass.respond_to? :all_understandings
understandings
end
end
def self.included(klass)
klass.extend ClassMethods
end
def must_understand(hash)
invalid_options = hash.inject([]) do |errors, (key, value)|
errors << key.to_s unless self.class.all_understandings.include?(key)
errors
end
raise ArgumentError.new("invalid options: #{invalid_options.join(', ')}") if invalid_options.any?
true
end
end
end
|