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.



7
8
9
10
11
12
# File 'lib/rspec_generate_doc/decorators/action.rb', line 7

def initialize(data = {})
  @name = (data[:name] || '').split('#').join(' ')
  @response = data[:response]
  @params = to_params(data[:api_params])
  @options = OpenStruct.new(data[:options] || {})
end

Instance Attribute Details

#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

#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

Instance Method Details

#bodyObject



46
47
48
# File 'lib/rspec_generate_doc/decorators/action.rb', line 46

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

#content_typeObject



38
39
40
# File 'lib/rspec_generate_doc/decorators/action.rb', line 38

def content_type
  @content_type ||= options.content_type || response.content_type
end

#content_type?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/rspec_generate_doc/decorators/action.rb', line 42

def content_type?
  content_type.present?
end

#hostObject



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

def host
  @host ||= options.host || request.host
end

#request_fullpathObject



18
19
20
# File 'lib/rspec_generate_doc/decorators/action.rb', line 18

def request_fullpath
  @request_fullpath ||= options.original_fullpath || request.original_fullpath.split('?').first
end

#request_methodObject



14
15
16
# File 'lib/rspec_generate_doc/decorators/action.rb', line 14

def request_method
  @request_method ||= options.request_method || request.request_method
end

#statusObject



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

def status
  @status ||= options.status || response.status
end

#status_messageObject



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

def status_message
  @status_message ||= options.status_message || response.status_message
end

#status_with_messageObject



34
35
36
# File 'lib/rspec_generate_doc/decorators/action.rb', line 34

def status_with_message
  @status_with_message ||= "#{status} #{status_message}"
end