Class: Apiwork::Introspection::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/apiwork/introspection/action.rb,
lib/apiwork/introspection/action/request.rb,
lib/apiwork/introspection/action/response.rb

Overview

Wraps action definitions within a resource.

Examples:

resource.actions[:show].method # => :get
resource.actions[:show].path # => "/posts/:id"
resource.actions[:create].request # => Action::Request

resource.actions.each_value do |action|
  action.method # => :get, :post, :patch, :delete
  action.request # => Action::Request
  action.response # => Action::Response
  action.deprecated? # => false
end

Defined Under Namespace

Classes: Request, Response

Instance Method Summary collapse

Constructor Details

#initialize(dump) ⇒ Action

Returns a new instance of Action.



20
21
22
# File 'lib/apiwork/introspection/action.rb', line 20

def initialize(dump)
  @dump = dump
end

Instance Method Details

#deprecated?Boolean

Whether this action is deprecated.

Returns:

  • (Boolean)


100
101
102
# File 'lib/apiwork/introspection/action.rb', line 100

def deprecated?
  @dump[:deprecated]
end

#descriptionString?

The description for this action.

Returns:

  • (String, nil)


76
77
78
# File 'lib/apiwork/introspection/action.rb', line 76

def description
  @dump[:description]
end

#methodSymbol

The method for this action.

Returns:

  • (Symbol)


36
37
38
# File 'lib/apiwork/introspection/action.rb', line 36

def method
  @dump[:method]
end

#operation_idString?

The operation ID for this action.

Returns:

  • (String, nil)


92
93
94
# File 'lib/apiwork/introspection/action.rb', line 92

def operation_id
  @dump[:operation_id]
end

#pathString

The path for this action.

Returns:

  • (String)


28
29
30
# File 'lib/apiwork/introspection/action.rb', line 28

def path
  @dump[:path]
end

#raisesArray<Symbol>

The raises for this action.

Returns:

  • (Array<Symbol>)


60
61
62
# File 'lib/apiwork/introspection/action.rb', line 60

def raises
  @dump[:raises]
end

#requestAction::Request

The request for this action.

Returns:



44
45
46
# File 'lib/apiwork/introspection/action.rb', line 44

def request
  @request ||= Request.new(@dump[:request])
end

#responseAction::Response

The response for this action.

Returns:



52
53
54
# File 'lib/apiwork/introspection/action.rb', line 52

def response
  @response ||= Response.new(@dump[:response])
end

#summaryString?

The summary for this action.

Returns:

  • (String, nil)


68
69
70
# File 'lib/apiwork/introspection/action.rb', line 68

def summary
  @dump[:summary]
end

#tagsArray<String>

The tags for this action.

Returns:

  • (Array<String>)


84
85
86
# File 'lib/apiwork/introspection/action.rb', line 84

def tags
  @dump[:tags]
end

#to_hHash

Converts this action to a hash.

Returns:

  • (Hash)


108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/apiwork/introspection/action.rb', line 108

def to_h
  {
    deprecated: deprecated?,
    description: description,
    method: method,
    operation_id: operation_id,
    path: path,
    raises: raises,
    request: request.to_h,
    response: response.to_h,
    summary: summary,
    tags: tags,
  }
end