Class: RspecGenerateDoc::Decorators::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_generate_doc/decorators/action.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Action

Returns a new instance of Action.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rspec_generate_doc/decorators/action.rb', line 8

def initialize(data = {})
  @name = (data[:name] || '').split('#').join(' ')
  @response = data[:response]
  @content_type = data[:content_type] || response.content_type
  @status = data[:status] || response.status
  @status_message = data[:status_message] || response.status_message
  @host = data[:host] || request.host
  @request_method = data[:request_method] || request.request_method
  @request_fullpath = data[:request_fullpath] || request.original_fullpath.split('?').first
  @params = to_params(data[:api_params])
  @options = OpenStruct.new(data[:options] || {})
end

Instance Attribute Details

#content_typeObject (readonly)

Returns the value of attribute content_type.



6
7
8
# File 'lib/rspec_generate_doc/decorators/action.rb', line 6

def content_type
  @content_type
end

#hostObject (readonly)

Returns the value of attribute host.



6
7
8
# File 'lib/rspec_generate_doc/decorators/action.rb', line 6

def host
  @host
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/rspec_generate_doc/decorators/action.rb', line 6

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/rspec_generate_doc/decorators/action.rb', line 6

def options
  @options
end

#paramsObject (readonly)

Returns the value of attribute params.



6
7
8
# File 'lib/rspec_generate_doc/decorators/action.rb', line 6

def params
  @params
end

#request_fullpathObject (readonly)

Returns the value of attribute request_fullpath.



6
7
8
# File 'lib/rspec_generate_doc/decorators/action.rb', line 6

def request_fullpath
  @request_fullpath
end

#request_methodObject (readonly)

Returns the value of attribute request_method.



6
7
8
# File 'lib/rspec_generate_doc/decorators/action.rb', line 6

def request_method
  @request_method
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/rspec_generate_doc/decorators/action.rb', line 6

def response
  @response
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/rspec_generate_doc/decorators/action.rb', line 6

def status
  @status
end

#status_messageObject (readonly)

Returns the value of attribute status_message.



6
7
8
# File 'lib/rspec_generate_doc/decorators/action.rb', line 6

def status_message
  @status_message
end

Instance Method Details

#bodyObject



29
30
31
# File 'lib/rspec_generate_doc/decorators/action.rb', line 29

def body
  @body ||= json_object.nil? ? response.body.to_s : JSON.pretty_generate(json_object)
end

#content_type?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/rspec_generate_doc/decorators/action.rb', line 25

def content_type?
  content_type.present?
end

#status_with_messageObject



21
22
23
# File 'lib/rspec_generate_doc/decorators/action.rb', line 21

def status_with_message
  "#{status} #{status_message}"
end