Sha256: 79b7ee06476abdb2029caf47a0333798d23b79941c74f24d1a0030576648b102

Contents?: true

Size: 868 Bytes

Versions: 1

Compression:

Stored size: 868 Bytes

Contents

require "shippinglogic/error"

module Shippinglogic
  # This module is more for application integration, so you can do something like:
  #
  #   tracking = fedex.tracking
  #   if tracking.valid?
  #     # render a successful response
  #   else
  #     # do something with the errors: fedex.errors
  #   end
  module Validation
    # Just an array of errors that were encounted if valid? returns false.
    def errors
      @errors ||= []
    end
    
    # Allows you to determine if the request is valid or not. All validation is delegated to the API
    # services, so what this does is make a call to the API and rescue any errors, then it puts those
    # errors into the 'errors' array.
    def valid?
      begin
        target
        true
      rescue Error => e
        errors.clear
        self.errors << e.message
        false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shippinglogic-1.2.3 lib/shippinglogic/validation.rb