Sha256: 1c99d086beed4ddfd39a573b982779d6a2cb225084254e62c662ea305901fe16

Contents?: true

Size: 774 Bytes

Versions: 12

Compression:

Stored size: 774 Bytes

Contents

module Roqua
  module CoreApi
    class Base < ActiveInteraction::Base
      private

      def create_enum(headers, rows)
        row_class = Struct.new(*headers.map(&:to_sym))
        rows.lazy.map { |row| row_class.new(*row) }.to_enum
      end

      def errors_to_object(response, obj)
        (response['errors'][obj.class.name.demodulize.underscore] || []).each do |attribute, errors|
          errors.each do |error|
            obj.errors.add(attribute.to_sym, error.to_sym)
          end
        end
      end

      def errors_to_usecase(response)
        (response['errors'] || []).each do |attribute, resp_errors|
          resp_errors.each do |error|
            errors.add(attribute.to_sym, error.to_sym)
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
roqua-core-api-0.7.0 lib/roqua/core_api/base.rb
roqua-core-api-0.6.0 lib/roqua/core_api/base.rb
roqua-core-api-0.5.0 lib/roqua/core_api/base.rb
roqua-core-api-0.4.0 lib/roqua/core_api/base.rb
roqua-core-api-0.3.1 lib/roqua/core_api/base.rb
roqua-core-api-0.3.0 lib/roqua/core_api/base.rb
roqua-core-api-0.2.4 lib/roqua/core_api/base.rb
roqua-core-api-0.2.3 lib/roqua/core_api/base.rb
roqua-core-api-0.2.2 lib/roqua/core_api/base.rb
roqua-core-api-0.2.1 lib/roqua/core_api/base.rb
roqua-core-api-0.2.0 lib/roqua/core_api/base.rb
roqua-core-api-0.1.1 lib/roqua/core_api/base.rb