Sha256: 1d0057c5e71a209ac811a36df78d8064a97303bf46299508bc724f630d4d8252

Contents?: true

Size: 1.11 KB

Versions: 20

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module ApipieDSL
  class ExceptionDescription
    attr_reader :error, :description, :metadata

    def self.from_dsl_data(args)
      error_or_options, desc, options = args
      ApipieDSL::ExceptionDescription.new(error_or_options, desc, options)
    end

    def initialize(error_or_options, desc = nil, options = {})
      if error_or_options.is_a?(Hash)
        error_or_options = error_or_options.transform_keys(&:to_sym)
        @error = error_or_options[:error]
        @metadata = error_or_options[:meta]
        @description = error_or_options[:desc] || error_or_options[:description]
      else
        @error = if error_or_options.is_a?(Symbol)
                   Rack::Utils::SYMBOL_TO_STATUS_CODE[error_or_options]
                 else
                   error_or_options
                 end
        raise ArgumentError, error_or_options unless @error

        @metadata = options[:meta]
        @description = desc
      end
    end

    def docs
      {
        error: error,
        description: ApipieDSL.markup_to_html(description),
        metadata: metadata
      }
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
apipie-dsl-2.6.2 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.6.1 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.6.0 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.5.0 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.4.0 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.3.0 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.2.10 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.2.9 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.2.8 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.2.7 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.2.6 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.2.5 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.2.4 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.2.3 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.2.2 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.2.1 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.2.0 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.1.1 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.1.0 lib/apipie_dsl/exception_description.rb
apipie-dsl-2.0.0 lib/apipie_dsl/exception_description.rb