Sha256: b905501346666adb7bb88058d10d2ce82f0c2fe81742b651a488038b51d8f50f

Contents?: true

Size: 827 Bytes

Versions: 8

Compression:

Stored size: 827 Bytes

Contents

module CouchPotato
  module Validation
    module WithValidatable
      def self.included(base)
        require 'validatable'
        base.send :include, ::Validatable
        base.class_eval do
          # Override the validate method to first run before_validation callback
          def valid?
            errors.clear
            run_callbacks :before_validation
            before_validation_errors = errors.errors.dup
            super
            before_validation_errors.each do |k, v|
              v.each {|message| errors.add(k, message)}
            end
            errors.empty?
          end
        end
      end
    end
  end
end

# add [] method to Validatable's implementation of the Errors class
module Validatable
  class Errors
    def [](attribute)
      [on(attribute)].flatten.compact
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
couch_potato-0.2.30 lib/couch_potato/validation/with_validatable.rb
couch_potato-0.2.29 lib/couch_potato/validation/with_validatable.rb
couch_potato-0.2.28 lib/couch_potato/validation/with_validatable.rb
couch_potato-0.2.27 lib/couch_potato/validation/with_validatable.rb
couch_potato-0.2.26 lib/couch_potato/validation/with_validatable.rb
couch_potato-0.2.25 lib/couch_potato/validation/with_validatable.rb
couch_potato-0.2.24 lib/couch_potato/validation/with_validatable.rb
couch_potato-0.2.23 lib/couch_potato/validation/with_validatable.rb