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



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

#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

#keyObject



25
26
27
# File 'lib/weak_parameters/base_validator.rb', line 25

def key
  path[-1]
end

#required?Boolean



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

def required?
  !!options[:required]
end

#typeObject



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

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

#validate(*path) ⇒ Object



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

def validate(*path)
  @path = path
  handle_failure unless valid?
end