Sha256: 62644a74a2471a0fc47def6b9dd2b4cf89dea5f57c3c9733fb8c55fbd577aed2

Contents?: true

Size: 672 Bytes

Versions: 15

Compression:

Stored size: 672 Bytes

Contents

require 'active_resource/base'

module ActiveResource
  class Errors < ActiveModel::Errors
    def from_json(json, save_cache = false)
      data = ActiveSupport::JSON.decode(json)['errors'] || {} rescue {}
      case data
      when String
        from_string(data, save_cache)
      else
        from_hash(data, save_cache)
      end
    end

    def from_hash(messages, save_cache = false)
      clear unless save_cache

      messages.each do |key,errors|
        errors.each do |error|
          add(key, error)
        end
      end
    end

    def from_string(error, save_cache = false)
      clear unless save_cache

      add("message", error)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
shopify_api-4.0.6 lib/active_resource/json_errors.rb
shopify_api-4.0.5 lib/active_resource/json_errors.rb
shopify_api-4.0.4 lib/active_resource/json_errors.rb
shopify_api-4.0.3 lib/active_resource/json_errors.rb
shopify_api-4.0.2 lib/active_resource/json_errors.rb
shopify_api-4.0.1 lib/active_resource/json_errors.rb
shopify_api-4.0.0 lib/active_resource/json_errors.rb
shopify_api-3.2.7 lib/active_resource/json_errors.rb
shopify_api-3.2.6 lib/active_resource/json_errors.rb
shopify_api-3.2.5 lib/active_resource/json_errors.rb
shopify_api-3.2.4 lib/active_resource/json_errors.rb
shopify_api-3.2.3 lib/active_resource/json_errors.rb
shopify_api-3.2.2 lib/active_resource/json_errors.rb
shopify_api-3.2.1 lib/active_resource/json_errors.rb
shopify_api-3.2.0 lib/active_resource/json_errors.rb