Class: Jsapi::DSL::Operation

Inherits:
Base
  • Object
show all
Includes:
SharedOperationMethods
Defined in:
lib/jsapi/dsl/operation.rb

Overview

Used to define an API operation.

Instance Method Summary collapse

Methods included from SharedOperationMethods

#model, #parameter, #request_body, #response

Methods inherited from Base

#import, #import_relative, #initialize, #respond_to_missing?

Constructor Details

This class inherits a constructor from Jsapi::DSL::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Jsapi::DSL::Base

Instance Method Details

#callback(name = nil, **keywords, &block) ⇒ Object

Specifies a callback.

callback 'foo' do
  operation '{$request.query.bar}'
end

Refers a resuable callback if the :ref keyword is specified.

callback ref: 'foo'

Refers the reusable callback object with the same name if neither any keywords nor a block is specified.

callback 'foo'

See Meta::Operation#callbacks for further information.



25
26
27
28
29
30
31
32
33
34
# File 'lib/jsapi/dsl/operation.rb', line 25

def callback(name = nil, **keywords, &block)
  define('callback', name&.inspect) do
    name = keywords[:ref] if name.nil?
    keywords = { ref: name } unless keywords.any? || block

    @meta_model.add_callback(name, keywords).tap do |callback_model|
      Base.new(callback_model, &block) if block
    end
  end
end

#method(arg) ⇒ Object

Specifies the HTTP verb of the operation.

method 'post'

See Meta::Operation#method for further information.



62
63
64
# File 'lib/jsapi/dsl/operation.rb', line 62

def method(arg)
  keyword(:method, arg)
end