Module: ValidationDelegation

Defined in:
lib/validation_delegation.rb,
lib/validation_delegation/version.rb

Defined Under Namespace

Modules: ClassMethods Classes: ErrorTransplanter

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/validation_delegation.rb', line 6

def self.included(base)
  base.send(:extend, ClassMethods)
end

Instance Method Details

#format_attribute(attribute_name) ⇒ Object



26
27
28
# File 'lib/validation_delegation.rb', line 26

def format_attribute(attribute_name)
  attribute_name.to_s.humanize.downcase.gsub(/\./, " ")
end

#receive_error(attribute, object_attribute, error) ⇒ Object



14
15
16
# File 'lib/validation_delegation.rb', line 14

def receive_error(attribute, object_attribute, error)
  attribute ? receive_error_on_attribute(attribute, object_attribute, error) : receive_error_on_self(object_attribute, error)
end

#receive_error_on_attribute(attribute, prefix, error) ⇒ Object



18
19
20
# File 'lib/validation_delegation.rb', line 18

def receive_error_on_attribute(attribute, prefix, error)
  errors[attribute] << [format_attribute(prefix), error].join(" ")
end

#receive_error_on_self(attribute, error) ⇒ Object



22
23
24
# File 'lib/validation_delegation.rb', line 22

def receive_error_on_self(attribute, error)
  errors[attribute] << error
end

#receive_errors(attribute, object_attribute, errors) ⇒ Object



10
11
12
# File 'lib/validation_delegation.rb', line 10

def receive_errors(attribute, object_attribute, errors)
  Array.wrap(errors).each{ |error| receive_error attribute, object_attribute, error }
end