Class: ValidationDelegation::ErrorTransplanter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(recipient, donor, options) ⇒ ErrorTransplanter

Returns a new instance of ErrorTransplanter.



56
57
58
59
60
# File 'lib/validation_delegation.rb', line 56

def initialize(recipient, donor, options)
  self.recipient = recipient
  self.donor     = donor
  self.options   = options
end

Instance Attribute Details

#donorObject

Returns the value of attribute donor.



54
55
56
# File 'lib/validation_delegation.rb', line 54

def donor
  @donor
end

#optionsObject

Returns the value of attribute options.



54
55
56
# File 'lib/validation_delegation.rb', line 54

def options
  @options
end

#recipientObject

Returns the value of attribute recipient.



54
55
56
# File 'lib/validation_delegation.rb', line 54

def recipient
  @recipient
end

Instance Method Details

#excepted_attribute?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/validation_delegation.rb', line 73

def excepted_attribute?(attribute)
  Array.wrap(options[:except]).include?(attribute.to_sym)
end

#ignore_attribute?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/validation_delegation.rb', line 69

def ignore_attribute?(attribute)
  excepted_attribute?(attribute) || !specified_attribute?(attribute)
end

#specified_attribute?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
80
# File 'lib/validation_delegation.rb', line 77

def specified_attribute?(attribute)
  return true unless options[:only]
  Array.wrap(options[:only]).include?(attribute.to_sym)
end

#transplantObject



62
63
64
65
66
67
# File 'lib/validation_delegation.rb', line 62

def transplant
  errors.each do |object_attribute, object_errors|
    next if ignore_attribute? object_attribute
    receive_errors options[:attribute], object_attribute, object_errors
  end
end