Class: OpenApi::DSL::CallbackObj

Inherits:
Hash
  • Object
show all
Includes:
Helpers
Defined in:
lib/oas_objs/callback_obj.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#_combined_schema, #arrow_writing_support, #process_schema_input

Constructor Details

#initialize(event_name, http_method, callback_url, &block) ⇒ CallbackObj

Returns a new instance of CallbackObj.



13
14
15
16
17
18
# File 'lib/oas_objs/callback_obj.rb', line 13

def initialize(event_name, http_method, callback_url, &block)
  self.event_name = event_name
  self.http_method = http_method
  self.callback_url = callback_url
  self.block = block
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



11
12
13
# File 'lib/oas_objs/callback_obj.rb', line 11

def block
  @block
end

#callback_urlObject

Returns the value of attribute callback_url.



11
12
13
# File 'lib/oas_objs/callback_obj.rb', line 11

def callback_url
  @callback_url
end

#event_nameObject

Returns the value of attribute event_name.



11
12
13
# File 'lib/oas_objs/callback_obj.rb', line 11

def event_name
  @event_name
end

#http_methodObject

Returns the value of attribute http_method.



11
12
13
# File 'lib/oas_objs/callback_obj.rb', line 11

def http_method
  @http_method
end

Instance Method Details

#processObject



20
21
22
23
24
25
26
27
28
# File 'lib/oas_objs/callback_obj.rb', line 20

def process
  {
      event_name => {
          processed_url => {
              http_method.downcase.to_sym => Api.new.run_dsl(&(self.block || -> { }))
          }
      }
  }
end

#processed_urlObject



30
31
32
33
34
35
36
37
# File 'lib/oas_objs/callback_obj.rb', line 30

def processed_url
  callback_url.gsub(/{[^{}]*}/) do |exp|
    key_location, key_name = exp[1..-2].split
    connector = key_location == 'body' ? '#/' : '.'
    key_location = '$request.' + key_location
    ['{', key_location, connector, key_name, '}'].join
  end
end