Sha256: c6c8937f63d841de46c6db33407278b1e756e7d1cbd658e9f585e897959759ee

Contents?: true

Size: 816 Bytes

Versions: 4

Compression:

Stored size: 816 Bytes

Contents

require 'deterministic'
require 'dry-struct'
require 'dry-types'
require 'json'

module Salestation
  class Web < Module
    module Types
      include Dry::Types.module
    end

    def initialize(errors: {})
      @error_mapper = ErrorMapper.new(errors)
    end

    def included(base)
      error_mapper = @error_mapper

      base.class_eval do
        const_set :Responses, Salestation::Web::Responses

        define_method(:process) do |response|
          result = response.map_err(error_mapper.map).value

          status result.status
          json JSON.dump(result.body)
        end
      end
    end
  end
end

require_relative './web/responses'
require_relative './web/error_mapper'
require_relative './result_helper'
require_relative './web/request_logger'
require_relative './web/statsd_middleware'

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
salestation-0.1.4 lib/salestation/web.rb
salestation-0.1.3 lib/salestation/web.rb
salestation-0.1.2 lib/salestation/web.rb
salestation-0.1.1 lib/salestation/web.rb