Class: APISpec::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/apispec/resource.rb

Instance Method Summary collapse

Constructor Details

#initialize(method, path, &block) ⇒ Resource

Returns a new instance of Resource.



2
3
4
5
6
7
# File 'lib/apispec/resource.rb', line 2

def initialize(method, path, &block)
  @method = method
  @path = path
  @response = {}
  instance_eval(&block)
end

Instance Method Details

#desc(value) ⇒ Object



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

def desc(value)
  @desc = value
end

#highlighted_pathObject



25
26
27
28
29
# File 'lib/apispec/resource.rb', line 25

def highlighted_path
  "#{@interface.base_uri}/#{@path}".gsub(/:[^\/0-9][^\/&\?]*/) do |value|
    "<span class=\"parameter\">#{value}</span>"
  end
end

#request(&block) ⇒ Object



13
14
15
# File 'lib/apispec/resource.rb', line 13

def request(&block)
  @request = APISpec::Message.new(&block)
end

#resolve_references!(root_namespace) ⇒ Object



31
32
33
34
35
36
# File 'lib/apispec/resource.rb', line 31

def resolve_references!(root_namespace)
  @request.resolve_references!(root_namespace) if @request
  @response.values.each do |response|
    response.resolve_references!(root_namespace)
  end
end

#response(http_code = 200, &block) ⇒ Object



17
18
19
# File 'lib/apispec/resource.rb', line 17

def response(http_code = 200, &block)
  @response[http_code] = APISpec::Message.new(&block)
end

#to_html(generator, interface) ⇒ Object



38
39
40
41
42
# File 'lib/apispec/resource.rb', line 38

def to_html(generator, interface)
  @interface = interface
  @generator = generator
  generator.template(binding, :resource)
end

#uidObject



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

def uid
  "#{@method}-#{@path}".gsub(/[^a-zA-Z0-9]/, "-").gsub(/[-]+/, "-")
end