Class: WeakParameters::BaseValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/weak_parameters/base_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, key, options = {}, &block) ⇒ BaseValidator

Returns a new instance of BaseValidator.



5
6
7
8
9
10
# File 'lib/weak_parameters/base_validator.rb', line 5

def initialize(controller, key, options = {}, &block)
  @controller = controller
  @key = key
  @options = options
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



3
4
5
# File 'lib/weak_parameters/base_validator.rb', line 3

def block
  @block
end

#controllerObject (readonly)

Returns the value of attribute controller.



3
4
5
# File 'lib/weak_parameters/base_validator.rb', line 3

def controller
  @controller
end

#keyObject (readonly)

Returns the value of attribute key.



3
4
5
# File 'lib/weak_parameters/base_validator.rb', line 3

def key
  @key
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/weak_parameters/base_validator.rb', line 3

def options
  @options
end

Instance Method Details

#required?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/weak_parameters/base_validator.rb', line 16

def required?
  !!options[:required]
end

#typeObject



20
21
22
# File 'lib/weak_parameters/base_validator.rb', line 20

def type
  self.class.name.split("::").last.sub(/Validator$/, "").underscore.to_sym
end

#validateObject



12
13
14
# File 'lib/weak_parameters/base_validator.rb', line 12

def validate
  handle_failure unless valid?
end