Class: APISpec::Message

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

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Message

Returns a new instance of Message.



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

def initialize(&block)
  @headers = []
  @parameters = []
  instance_eval(&block)
end

Instance Method Details

#array(value) ⇒ Object



24
25
26
# File 'lib/apispec/message.rb', line 24

def array(value)
  @array = value
end

#content_desc(value) ⇒ Object



28
29
30
# File 'lib/apispec/message.rb', line 28

def content_desc(value)
  @content_desc = value
end

#desc(value) ⇒ Object



16
17
18
# File 'lib/apispec/message.rb', line 16

def desc(value)
  @desc = value
end

#example(format, value) ⇒ Object



32
33
34
# File 'lib/apispec/message.rb', line 32

def example(format, value)
  @example = APISpec::Example.new(format, value)
end

#example_file(format, path) ⇒ Object



36
37
38
# File 'lib/apispec/message.rb', line 36

def example_file(format, path)
  @example = [format, path]
end

#headers(*value) ⇒ Object



8
9
10
# File 'lib/apispec/message.rb', line 8

def headers(*value)
  @headers = value
end

#object(value) ⇒ Object



20
21
22
# File 'lib/apispec/message.rb', line 20

def object(value)
  @object = value
end

#params(*value) ⇒ Object



12
13
14
# File 'lib/apispec/message.rb', line 12

def params(*value)
  @parameters = value
end

#resolve_references!(root_namespace) ⇒ Object



40
41
42
43
44
45
# File 'lib/apispec/message.rb', line 40

def resolve_references!(root_namespace)
  @headers    = @headers.map    { |name| root_namespace.find_field(name) }.flatten
  @parameters = @parameters.map { |name| root_namespace.find_field(name) }.flatten
  @object     = root_namespace.find_object(@object) if @object
  @array      = root_namespace.find_object(@array) if @array
end

#to_html(generator, resource) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/apispec/message.rb', line 47

def to_html(generator, resource)
  @generator = generator
  @resource = resource
  if @example.is_a? Array
    format, path = @example
    @example = APISpec::Example.new(format, File.read(@generator.path(path)))
  end
  generator.template(binding, :message)
end