Class: Docit::Operation

Inherits:
Object
  • Object
show all
Defined in:
lib/docit/operation.rb

Overview

Represents the documentation for a single controller action. Created by doc_for and stored in the Registry.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller:, action:) ⇒ Operation

Returns a new instance of Operation.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/docit/operation.rb', line 11

def initialize(controller:, action:)
  @controller = controller
  @action = action.to_s
  @_tags = []
  @_responses = []
  @_parameters = Builders::ParameterBuilder.new
  @_request_body = nil
  @_security = []
  @_deprecated = false
  @_operation_id = nil
end

Instance Attribute Details

#_deprecatedObject (readonly)

Returns the value of attribute _deprecated.



7
8
9
# File 'lib/docit/operation.rb', line 7

def _deprecated
  @_deprecated
end

#_descriptionObject (readonly)

Returns the value of attribute _description.



7
8
9
# File 'lib/docit/operation.rb', line 7

def _description
  @_description
end

#_operation_idObject (readonly)

Returns the value of attribute _operation_id.



7
8
9
# File 'lib/docit/operation.rb', line 7

def _operation_id
  @_operation_id
end

#_parametersObject (readonly)

Returns the value of attribute _parameters.



7
8
9
# File 'lib/docit/operation.rb', line 7

def _parameters
  @_parameters
end

#_request_bodyObject (readonly)

Returns the value of attribute _request_body.



7
8
9
# File 'lib/docit/operation.rb', line 7

def _request_body
  @_request_body
end

#_responsesObject (readonly)

Returns the value of attribute _responses.



7
8
9
# File 'lib/docit/operation.rb', line 7

def _responses
  @_responses
end

#_securityObject (readonly)

Returns the value of attribute _security.



7
8
9
# File 'lib/docit/operation.rb', line 7

def _security
  @_security
end

#_summaryObject (readonly)

Returns the value of attribute _summary.



7
8
9
# File 'lib/docit/operation.rb', line 7

def _summary
  @_summary
end

#_tagsObject (readonly)

Returns the value of attribute _tags.



7
8
9
# File 'lib/docit/operation.rb', line 7

def _tags
  @_tags
end

#actionObject (readonly)

Returns the value of attribute action.



7
8
9
# File 'lib/docit/operation.rb', line 7

def action
  @action
end

#controllerObject (readonly)

Returns the value of attribute controller.



7
8
9
# File 'lib/docit/operation.rb', line 7

def controller
  @controller
end

Instance Method Details

#deprecated(value: true) ⇒ Object



35
36
37
# File 'lib/docit/operation.rb', line 35

def deprecated(value: true)
  @_deprecated = value
end

#description(text) ⇒ Object



27
28
29
# File 'lib/docit/operation.rb', line 27

def description(text)
  @_description = text
end

#operation_id(text) ⇒ Object



39
40
41
# File 'lib/docit/operation.rb', line 39

def operation_id(text)
  @_operation_id = text
end

#parameter(name, location:, type: :string, required: false, description: nil, **opts) ⇒ Object



47
48
49
# File 'lib/docit/operation.rb', line 47

def parameter(name, location:, type: :string, required: false, description: nil, **opts)
  @_parameters.add(name, location: location, type: type, required: required, description: description, **opts)
end

#request_body(required: false, content_type: "application/json", &block) ⇒ Object



51
52
53
54
55
# File 'lib/docit/operation.rb', line 51

def request_body(required: false, content_type: "application/json", &block)
  builder = Builders::RequestBodyBuilder.new(required: required, content_type: content_type)
  builder.instance_eval(&block) if block_given?
  @_request_body = builder
end

#response(status, description = "", &block) ⇒ Object



57
58
59
60
61
# File 'lib/docit/operation.rb', line 57

def response(status, description = "", &block)
  builder = Builders::ResponseBuilder.new(status: status, description: description)
  builder.instance_eval(&block) if block_given?
  @_responses << builder
end

#security(scheme) ⇒ Object



43
44
45
# File 'lib/docit/operation.rb', line 43

def security(scheme)
  @_security << scheme
end

#summary(text) ⇒ Object



23
24
25
# File 'lib/docit/operation.rb', line 23

def summary(text)
  @_summary = text
end

#tags(*tags_list) ⇒ Object



31
32
33
# File 'lib/docit/operation.rb', line 31

def tags(*tags_list)
  @_tags = tags_list.flatten
end