Class: Swagger::Docs::SwaggerDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/swagger/docs/dsl.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(action, caller, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/swagger/docs/dsl.rb', line 5

def self.call(action, caller, &block)
  # Create a new SwaggerDSL instance, and instance_eval the block to it
  instance = new
  instance.instance_eval(&block)
  # Now return all of the set instance variables as a Hash
  instance.instance_variables.inject({}) { |result_hash, instance_variable|
    result_hash[instance_variable] = instance.instance_variable_get(instance_variable)
    result_hash # Gotta have the block return the result_hash
  }
end

Instance Method Details

#method(method) ⇒ Object



24
25
26
# File 'lib/swagger/docs/dsl.rb', line 24

def method(method)
  @method = method
end

#nickname(nickname) ⇒ Object



32
33
34
# File 'lib/swagger/docs/dsl.rb', line 32

def nickname(nickname)
  @nickname = nickname
end

#notes(text) ⇒ Object



20
21
22
# File 'lib/swagger/docs/dsl.rb', line 20

def notes(text)
  @notes = text
end

#param(param_type, name, type, required, description = nil, hash = {}) ⇒ Object



40
41
42
43
# File 'lib/swagger/docs/dsl.rb', line 40

def param(param_type, name, type, required, description = nil, hash={})
  parameters << {:param_type => param_type, :name => name, :type => type,
    :description => description, :required => required == :required}.merge(hash)
end

#param_list(param_type, name, type, required, description = nil, allowed_values = [], hash = {}) ⇒ Object

helper method to generate enums



46
47
48
49
# File 'lib/swagger/docs/dsl.rb', line 46

def param_list(param_type, name, type, required, description = nil, allowed_values = [], hash = {})
  hash.merge!({allowable_values: {value_type: "LIST", values: allowed_values}})
  param(param_type, name, type, required, description, hash)
end

#parametersObject



36
37
38
# File 'lib/swagger/docs/dsl.rb', line 36

def parameters
  @parameters ||= []
end

#response(status, text = nil, model = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/swagger/docs/dsl.rb', line 55

def response(status, text = nil, model = nil)
  if status.is_a? Symbol
    status_code = Rack::Utils.status_code(status)
    response_messages << {:code => status_code, :message => text || status.to_s.titleize}
  else
    response_messages << {:code => status, :message => text}
  end
  response_messages.sort_by!{|i| i[:code]}
end

#response_messagesObject



51
52
53
# File 'lib/swagger/docs/dsl.rb', line 51

def response_messages
  @response_messages ||= []
end

#summary(text) ⇒ Object



16
17
18
# File 'lib/swagger/docs/dsl.rb', line 16

def summary(text)
  @summary = text
end

#type(type) ⇒ Object



28
29
30
# File 'lib/swagger/docs/dsl.rb', line 28

def type(type)
  @type = type
end