Class: Swagger::Docs::SwaggerModelDSL

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject

Returns the value of attribute id


76
77
78
# File 'lib/swagger/docs/dsl.rb', line 76

def id
  @id
end

Class Method Details

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


79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/swagger/docs/dsl.rb', line 79

def self.call(model_name, caller, &block)
  # Create a new SwaggerModelDSL instance, and instance_eval the block to it
  instance = new
  instance.instance_eval(&block)
  instance.id = model_name
  # Now return all of the set instance variables as a Hash
  instance.instance_variables.inject({}) { |result_hash, instance_var_name|
    key = instance_var_name[1..-1].to_sym  # Strip prefixed @ sign.
    result_hash[key] = instance.instance_variable_get(instance_var_name)
    result_hash # Gotta have the block return the result_hash
  }
end

Instance Method Details

#description(description) ⇒ Object


100
101
102
# File 'lib/swagger/docs/dsl.rb', line 100

def description(description)
  @description = description
end

#propertiesObject


92
93
94
# File 'lib/swagger/docs/dsl.rb', line 92

def properties
  @properties ||= {}
end

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


104
105
106
107
108
109
110
# File 'lib/swagger/docs/dsl.rb', line 104

def property(name, type, required, description = nil, hash={})
  properties[name] = {
    type: type,
    description: description,
  }.merge!(hash)
  self.required << name if required == :required
end

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

helper method to generate enums


113
114
115
116
# File 'lib/swagger/docs/dsl.rb', line 113

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

#requiredObject


96
97
98
# File 'lib/swagger/docs/dsl.rb', line 96

def required
  @required ||= []
end