Module: Validatable::Requireable

Included in:
ValidationBase
Defined in:
lib/validatable/requireable.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



13
14
15
# File 'lib/validatable/requireable.rb', line 13

def self.included(klass)
  klass.extend ClassMethods
end

Instance Method Details

#requires(options) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
# File 'lib/validatable/requireable.rb', line 17

def requires(options)
  required_options = self.class.required_options.inject([]) do |errors, attribute|
    errors << attribute.to_s unless options.has_key?(attribute)
    errors
  end
  raise ArgumentError.new("#{self.class} requires options: #{required_options.join(', ')}") if required_options.any?
  true
end