Sha256: 4a4fac1824290f0651b1b640a67f4255a5ae4c233cb9b400fd19fc6067456b69
Contents?: true
Size: 1.4 KB
Versions: 15
Compression:
Stored size: 1.4 KB
Contents
module PivotalTracker class Errors include Enumerable attr_reader :errors alias :messages :errors def initialize @errors = [] end def each @errors.each do |error| yield error end end def empty? @errors.empty? end def add_from_xml(xml) Nokogiri::XML(xml).xpath("/errors/error").each do |error| @errors << error.text end end end module Validation def self.included(klass) klass.class_eval do instance_methods = klass.instance_methods.map {|name| name.to_sym} if instance_methods.include?(:create) alias_method :create_without_validations, :create alias_method :create, :create_with_validations end if instance_methods.include?(:update) alias_method :update_without_validations, :update alias_method :update, :update_with_validations end end end def create_with_validations begin create_without_validations rescue RestClient::UnprocessableEntity => e errors.add_from_xml e.response self end end def update_with_validations(attrs={}) begin update_without_validations attrs rescue RestClient::UnprocessableEntity => e errors.add_from_xml e.response self end end def errors @errors ||= Errors.new end end end
Version data entries
15 entries across 15 versions & 3 rubygems