Class: Judge::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/judge/validator.rb

Constant Summary collapse

REJECTED_OPTIONS =
[:if, :on, :unless, :tokenizer, :scope, :case_sensitive, :judge]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, method, amv) ⇒ Validator



9
10
11
12
13
14
15
# File 'lib/judge/validator.rb', line 9

def initialize(object, method, amv)
  @kind     = amv.kind
  @options  = amv.options.reject { |key| REJECTED_OPTIONS.include?(key)  }
  @method   = method
  @messages = Judge::MessageCollection.new(object, method, amv)
  @original_value    = object.send(method)
end

Instance Attribute Details

#active_model_validatorObject (readonly)

Returns the value of attribute active_model_validator.



5
6
7
# File 'lib/judge/validator.rb', line 5

def active_model_validator
  @active_model_validator
end

#kindObject (readonly)

Returns the value of attribute kind.



5
6
7
# File 'lib/judge/validator.rb', line 5

def kind
  @kind
end

#messagesObject (readonly)

Returns the value of attribute messages.



5
6
7
# File 'lib/judge/validator.rb', line 5

def messages
  @messages
end

#methodObject (readonly)

Returns the value of attribute method.



5
6
7
# File 'lib/judge/validator.rb', line 5

def method
  @method
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/judge/validator.rb', line 5

def options
  @options
end

#original_valueObject (readonly)

Returns the value of attribute original_value.



5
6
7
# File 'lib/judge/validator.rb', line 5

def original_value
  @original_value
end

Instance Method Details

#to_hashObject



17
18
19
20
21
22
23
24
25
# File 'lib/judge/validator.rb', line 17

def to_hash
  params = {
    :kind => kind,
    :options => options,
    :messages => messages.to_hash
  }
  params[:original_value] = original_value if kind == :uniqueness
  params
end