Sha256: 0e3df0d3fcdd7ac21db61621e3948837f350f06860df642249d7e93c8b33d3d8

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

module Restly::Base::Instance::ErrorHandling
  extend ActiveSupport::Concern

  private

  def response_has_errors?(response=self.response)
    @response.status >= 400 ||
      (parsed_response(response).is_a?(Hash) &&
        (parsed_response(response)[:errors] || parsed_response(response)[:error]))
  end

  def set_errors_from_response(response = self.response)

    response_errors = parsed_response(response)[:errors] || parsed_response(response)[:error]

    case response_errors

      when Hash
        response_errors.each do |name, error|
          case error

            when Array
              error.each { |e| self.errors.add(name.to_sym, e) }

            when String
              self.errors.add(name.to_sym, error)

          end
        end

      when Array
        response_errors.each do |error|
          self.errors.add(:base, error)
        end

      when String
        self.errors.add(:base, response_errors)

    end

    self.errors
  end

  def read_attribute_for_validation(attr)
    send attr
  end

  module ClassMethods

    def human_attribute_name(attr, options = {})
      attr.to_s.humanize
    end

    def lookup_ancestors
      [self]
    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
restly-0.0.1.beta.3 lib/restly/base/instance/error_handling.rb
restly-0.0.1.beta.2 lib/restly/base/instance/error_handling.rb
restly-0.0.1.beta.1 lib/restly/base/instance/error_handling.rb
restly-0.0.1.alpha.22 lib/restly/base/instance/error_handling.rb
restly-0.0.1.alpha.19 lib/restly/base/instance/error_handling.rb
restly-0.0.1.alpha.18 lib/restly/base/instance/error_handling.rb