Sha256: f5836003db2b7f97a4a96ddf726fecb62b680dbdbeef3c575b3d280a5d41950b

Contents?: true

Size: 1.9 KB

Versions: 5

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Examples
    module Standard
      class RequestParams
        module Services
          class Prepare
            include ConvenientService::Standard::Config

            attr_reader :request

            step Services::ExtractParamsFromPath, \
              in: [:request, {pattern: raw(/^\/rules\/(?<id>\d+)\.(?<format>\w+)$/)}],
              out: {params: :params_from_path}

            step Services::ExtractParamsFromBody, \
              in: :request,
              out: {params: :params_from_body}

            step Services::MergeParams, \
              in: [:params_from_path, :params_from_body],
              out: :params

            step Services::LogRequestParams, \
              in: [:request, :params, tag: raw("Uncasted")]

            step Services::FilterOutUnpermittedParams, \
              in: [:params, {permitted_keys: raw([:id, :format, :title, :description, :tags, :sources])}],
              out: reassign(:params)

            step Services::ApplyDefaultParamValues, \
              in: [:params, defaults: raw({format: "json", tags: [], sources: []})],
              out: reassign(:params)

            step Services::ValidateUncastedParams, \
              in: :params

            step Services::CastParams, \
              in: :params,
              out: [:original_params, {casted_params: reassign(:params)}]

            step Services::LogRequestParams, \
              in: [:request, :params, tag: raw("Casted")]

            step Services::ValidateCastedParams, \
              in: [:original_params, {casted_params: :params}]

            step :result, \
              in: :params,
              out: reassign(:params)

            def initialize(request:)
              @request = request
            end

            def result
              success(params: params)
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
convenient_service-0.17.0 lib/convenient_service/examples/standard/request_params/services/prepare.rb
convenient_service-0.16.0 lib/convenient_service/examples/standard/request_params/services/prepare.rb
convenient_service-0.15.0 lib/convenient_service/examples/standard/request_params/services/prepare.rb
convenient_service-0.14.0 lib/convenient_service/examples/standard/request_params/services/prepare.rb
convenient_service-0.13.0 lib/convenient_service/examples/standard/request_params/services/prepare.rb