Class: Pragma::Operation::Base Abstract

Inherits:
Object
  • Object
show all
Includes:
Interactor, Authorization, Decoration, Validation
Defined in:
lib/pragma/operation/base.rb

Overview

This class is abstract.

Subclass and override #call to implement an operation.

This is the base class all your operations should extend.

Author:

  • Alessandro Desantis

Constant Summary collapse

STATUSES =
{
  200 => :ok,
  201 => :created,
  202 => :accepted,
  203 => :non_authoritative_information,
  204 => :no_content,
  205 => :reset_content,
  206 => :partial_content,
  207 => :multi_status,
  208 => :already_reported,
  300 => :multiple_choices,
  301 => :moved_permanently,
  302 => :found,
  303 => :see_other,
  304 => :not_modified,
  305 => :use_proxy,
  307 => :temporary_redirect,
  400 => :bad_request,
  401 => :unauthorized,
  402 => :payment_required,
  403 => :forbidden,
  404 => :not_found,
  405 => :method_not_allowed,
  406 => :not_acceptable,
  407 => :proxy_authentication_required,
  408 => :request_timeout,
  409 => :conflict,
  410 => :gone,
  411 => :length_required,
  412 => :precondition_failed,
  413 => :request_entity_too_large,
  414 => :request_uri_too_large,
  415 => :unsupported_media_type,
  416 => :request_range_not_satisfiable,
  417 => :expectation_failed,
  418 => :im_a_teapot,
  422 => :unprocessable_entity,
  423 => :locked,
  424 => :failed_dependency,
  425 => :unordered_collection,
  426 => :upgrade_required,
  428 => :precondition_required,
  429 => :too_many_requests,
  431 => :request_header_fields_too_large,
  449 => :retry_with,
  500 => :internal_server_error,
  501 => :not_implemented,
  502 => :bad_gateway,
  503 => :service_unavailable,
  504 => :gateway_timeout,
  505 => :http_version_not_supported,
  506 => :variant_also_negotiates,
  507 => :insufficient_storage,
  509 => :bandwidth_limit_exceeded,
  510 => :not_extended,
  511 => :network_authentication_required
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Decoration

included

Methods included from Validation

included

Methods included from Authorization

included

Class Method Details

.inherited(child) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/pragma/operation/base.rb', line 75

def inherited(child)
  child.class_eval do
    before :setup_context
    around :handle_halt
    after :mark_result, :consolidate_status, :validate_status, :set_default_status
    after :build_links
  end
end

.operation_nameSymbol

Returns the name of this operation.

For instance, if the operation is called API::V1::Post::Operation::Create, returns create.

Returns:

  • (Symbol)


90
91
92
93
94
95
96
97
# File 'lib/pragma/operation/base.rb', line 90

def operation_name
  name.split('::').last
    .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
    .gsub(/([a-z\d])([A-Z])/, '\1_\2')
    .tr('-', '_')
    .downcase
    .to_sym
end

Instance Method Details

#callObject

Runs the operation.



101
102
103
# File 'lib/pragma/operation/base.rb', line 101

def call
  fail NotImplementedError
end