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

Constant Summary collapse

MAX_PRECEDENCE =
9_999

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rspec_example) ⇒ Resource


11
12
13
14
# File 'lib/rspec_api_docs/formatter/resource.rb', line 11

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

Instance Attribute Details

#rspec_exampleObject (readonly)

Returns the value of attribute rspec_example


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

def rspec_example
  @rspec_example
end

Instance Method Details

#add_example(example) ⇒ void

This method returns an undefined value.

Add an example


44
45
46
# File 'lib/rspec_api_docs/formatter/resource.rb', line 44

def add_example(example)
  @examples << example
end

#descriptionString

The description of the resource.

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


30
31
32
# File 'lib/rspec_api_docs/formatter/resource.rb', line 30

def description
  [:resource_description]
end

#examplesArray<Example>

Returns an array of Examples


37
38
39
# File 'lib/rspec_api_docs/formatter/resource.rb', line 37

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

#inspectObject


60
61
62
# File 'lib/rspec_api_docs/formatter/resource.rb', line 60

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

#nameString

The name of the resource.

E.g. “Characters”


21
22
23
# File 'lib/rspec_api_docs/formatter/resource.rb', line 21

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

#precedenceInteger


49
50
51
# File 'lib/rspec_api_docs/formatter/resource.rb', line 49

def precedence
  @precedence ||= .fetch(:resource_precedence, MAX_PRECEDENCE)
end

#precedence=(value) ⇒ void

This method returns an undefined value.

Set the resource precedence


56
57
58
# File 'lib/rspec_api_docs/formatter/resource.rb', line 56

def precedence=(value)
  @precedence = value
end