Class: RspecApiDocumentation::Example

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_api_documentation/example.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example, configuration) ⇒ Example

Returns a new instance of Example.



5
6
7
8
# File 'lib/rspec_api_documentation/example.rb', line 5

def initialize(example, configuration)
  @example = example
  @configuration = configuration
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *args, &block) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/rspec_api_documentation/example.rb', line 10

def method_missing(method_sym, *args, &block)
  if example..has_key?(method_sym)
    example.[method_sym]
  else
    example.send(method_sym, *args, &block)
  end
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



3
4
5
# File 'lib/rspec_api_documentation/example.rb', line 3

def configuration
  @configuration
end

#exampleObject (readonly)

Returns the value of attribute example.



3
4
5
# File 'lib/rspec_api_documentation/example.rb', line 3

def example
  @example
end

Instance Method Details

#explanationObject



53
54
55
# File 'lib/rspec_api_documentation/example.rb', line 53

def explanation
  [:explanation] || nil
end

#has_attributes?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/rspec_api_documentation/example.rb', line 41

def has_attributes?
  respond_to?(:attributes) && attributes.present?
end

#has_parameters?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/rspec_api_documentation/example.rb', line 37

def has_parameters?
  respond_to?(:parameters) && parameters.present?
end

#has_response_fields?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/rspec_api_documentation/example.rb', line 45

def has_response_fields?
  respond_to?(:response_fields) && response_fields.present?
end

#http_methodObject



22
23
24
# File 'lib/rspec_api_documentation/example.rb', line 22

def http_method
  [:method].to_s.upcase
end

#public?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/rspec_api_documentation/example.rb', line 33

def public?
  [:public]
end

#requestsObject



57
58
59
# File 'lib/rspec_api_documentation/example.rb', line 57

def requests
  filter_headers([:requests]) || []
end

#resource_explanationObject



49
50
51
# File 'lib/rspec_api_documentation/example.rb', line 49

def resource_explanation
  [:resource_explanation] || nil
end

#respond_to?(method_sym, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/rspec_api_documentation/example.rb', line 18

def respond_to?(method_sym, include_private = false)
  super || example..has_key?(method_sym) || example.respond_to?(method_sym, include_private)
end

#should_document?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
# File 'lib/rspec_api_documentation/example.rb', line 26

def should_document?
  return false if pending? || ![:resource_name] || ![:document]
  return false if (Array([:document]) & Array(configuration.exclusion_filter)).length > 0
  return true if (Array([:document]) & Array(configuration.filter)).length > 0
  return true if configuration.filter == :all
end