Sha256: 3adc82b5f637d99794a0a2476892af5588c7f1a83aa97a9643b8410b76788669

Contents?: true

Size: 862 Bytes

Versions: 1

Compression:

Stored size: 862 Bytes

Contents

module Axel
  module ServiceResource
    class Builder < Typhoid::Builder
      def result
        enveloped? ? parsed_body["result"] : parsed_body
      end

      def enveloped?
        parsed_body.respond_to?("has_key?") && parsed_body.has_key?("metadata") && parsed_body.has_key?("result")
      end

      def array?
        result.is_a?(Array)
      end

      def singular?
        !array?
      end

      def metadata
        parsed_body["metadata"] if enveloped?
      end

      def errors
        parsed_body["errors"] if enveloped?
      end

      def compiled_payloads
        Array(result).map { |res| { "metadata" => metadata, "errors" => errors, "result" => res } }
      end

      def build_array
        compiled_payloads.collect { |single|
          build_from_klass(single)
        }
      end
      private :build_array
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
axel-0.0.1 app/models/axel/service_resource/builder.rb