Module: ValidationGroup::ActiveRecord::Errors

Defined in:
lib/spree_core/validation_group.rb

Overview

included in ActiveRecord::Errors

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



118
119
120
121
122
# File 'lib/spree_core/validation_group.rb', line 118

def self.included(base) #:nodoc:
  base.class_eval do
    alias_method_chain :add, :validation_group
  end
end

Instance Method Details

#add_with_validation_group(attribute, msg = , *args, &block) ⇒ Object



104
105
106
107
108
109
110
# File 'lib/spree_core/validation_group.rb', line 104

def add_with_validation_group(attribute,
    msg = @@default_error_messages[:invalid], *args,
    &block)
  # jeffp: setting @current_validation_fields and use of should_validate? optimizes code
  add_error = @base.respond_to?(:should_validate?) ? @base.should_validate?(attribute.to_sym) : true
  add_without_validation_group(attribute, msg, *args, &block) if add_error
end

#remove_on(attributes) ⇒ Object



112
113
114
115
116
# File 'lib/spree_core/validation_group.rb', line 112

def remove_on(attributes)
  return unless attributes
  attributes = [attributes] unless attributes.is_a?(Array)
  @errors.reject!{|k,v| !attributes.include?(k.to_sym)}
end