Class: Assent::Errors

Inherits:
Object
  • Object
show all
Includes:
Config
Defined in:
lib/assent/validations/errors.rb

Instance Method Summary collapse

Methods included from Config

add, config, config_file

Constructor Details

#initializeErrors

Returns a new instance of Errors.



7
8
9
10
# File 'lib/assent/validations/errors.rb', line 7

def initialize
  @errors = Hash.new
  super
end

Instance Method Details

#add(field, rule) ⇒ Object



12
13
14
15
16
17
# File 'lib/assent/validations/errors.rb', line 12

def add(field, rule)
  text = String.new(Config.config[rule.to_s])
  replace(text, field)
  @errors[field] ||= []
  @errors[field].push(text)
end

#errorsObject



19
20
21
# File 'lib/assent/validations/errors.rb', line 19

def errors
  @errors
end

#replace(text, field) ⇒ Object



23
24
25
26
# File 'lib/assent/validations/errors.rb', line 23

def replace(text, field)
  message = text.sub! ':field', field.to_s
  return message
end