Sha256: 830f1a1bfb6376b85619764b16602e829a54f886bdeddd3f53e956a12ca25218

Contents?: true

Size: 1.82 KB

Versions: 7

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

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

            attr_reader :id, :format, :title, :description, :tags, :sources

            step :validate_id, in: :id
            step :validate_format, in: :format
            step :validate_title, in: :title
            step :validate_description, in: :description

            def initialize(params:)
              @id = params[:id]
              @format = params[:format]
              @title = params[:title]
              @description = params[:description]
              @tags = params[:tags]
              @sources = params[:sources]
            end

            private

            def validate_id
              return error("ID is NOT present") if Utils::Object.present?(id)
              return error("ID `#{id}` is NOT a valid integer") unless Utils::Integer.safe_parse(id)

              success
            end

            def validate_format
              return error("Format `#{format}` is NOT supported, only JSON is allowed") if format != "json"

              success
            end

            def validate_title
              return error("Title is NOT present") if Utils::Object.present?(title)

              success
            end

            def validate_description
              return error("Description is NOT present") if Utils::Object.present?(description)

              success
            end

            ##
            # TODO:
            #
            def validate_tags
              success
            end

            ##
            # TODO:
            #
            def validate_sources
              success
            end
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
convenient_service-0.12.0 lib/convenient_service/examples/standard/request_params/services/validate_uncasted_params.rb
convenient_service-0.10.1 lib/convenient_service/examples/standard/request_params/services/validate_uncasted_params.rb
convenient_service-0.10.0 lib/convenient_service/examples/standard/request_params/services/validate_uncasted_params.rb
convenient_service-0.9.0 lib/convenient_service/examples/standard/request_params/services/validate_uncasted_params.rb
convenient_service-0.8.0 lib/convenient_service/examples/standard/request_params/services/validate_uncasted_params.rb
convenient_service-0.7.0 lib/convenient_service/examples/standard/request_params/services/validate_uncasted_params.rb
convenient_service-0.6.0 lib/convenient_service/examples/standard/request_params/services/validate_uncasted_params.rb