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.



63
64
65
# File 'lib/swagger/docs/dsl.rb', line 63

def id
  @id
end

Class Method Details

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



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/swagger/docs/dsl.rb', line 66

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



87
88
89
# File 'lib/swagger/docs/dsl.rb', line 87

def description(description)
  @description = description
end

#propertiesObject



79
80
81
# File 'lib/swagger/docs/dsl.rb', line 79

def properties
  @properties ||= {}
end

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



91
92
93
94
95
96
97
# File 'lib/swagger/docs/dsl.rb', line 91

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

#requiredObject



83
84
85
# File 'lib/swagger/docs/dsl.rb', line 83

def required
  @required ||= []
end