Class: RspecApiDocs::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_api_docs/formatter/resource.rb,
lib/rspec_api_docs/formatter/resource/example.rb,
lib/rspec_api_docs/formatter/resource/parameter.rb,
lib/rspec_api_docs/formatter/resource/response_field.rb,
lib/rspec_api_docs/formatter/resource/example/deep_hash_set.rb,
lib/rspec_api_docs/formatter/resource/example/request_headers.rb

Defined Under Namespace

Classes: Example, Parameter, ResponseField

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rspec_example) ⇒ Resource

Returns a new instance of Resource.



9
10
11
12
# File 'lib/rspec_api_docs/formatter/resource.rb', line 9

def initialize(rspec_example)
  @rspec_example = rspec_example
  @examples = []
end

Instance Attribute Details

#rspec_exampleObject (readonly)

Returns the value of attribute rspec_example.



7
8
9
# File 'lib/rspec_api_docs/formatter/resource.rb', line 7

def rspec_example
  @rspec_example
end

Instance Method Details

#add_example(example) ⇒ void

This method returns an undefined value.

Add an example



42
43
44
# File 'lib/rspec_api_docs/formatter/resource.rb', line 42

def add_example(example)
  @examples << example
end

#descriptionString

The description of the resource.

E.g. “Orders can be created, viewed, and deleted”

Returns:

  • (String)


28
29
30
# File 'lib/rspec_api_docs/formatter/resource.rb', line 28

def description
  [:resource_description]
end

#examplesArray<Example>

Returns an array of Examples

Returns:



35
36
37
# File 'lib/rspec_api_docs/formatter/resource.rb', line 35

def examples
  @examples.sort_by { |example| [example.precedence, example.name].join }
end

#inspectObject



51
52
53
# File 'lib/rspec_api_docs/formatter/resource.rb', line 51

def inspect
  "#<RspecApiDocs::Resource #{name.inspect}, @examples=#{examples.inspect}>"
end

#nameString

The name of the resource.

E.g. “Characters”

Returns:

  • (String)


19
20
21
# File 'lib/rspec_api_docs/formatter/resource.rb', line 19

def name
  .fetch(:resource_name, rspec_example.[:example_group][:description])
end

#precedenceString?

Returns:

  • (String, nil)


47
48
49
# File 'lib/rspec_api_docs/formatter/resource.rb', line 47

def precedence
  [:resource_precedence]
end