Class: Swagger::Docs::SwaggerModelDSL
- Inherits:
-
Object
- Object
- Swagger::Docs::SwaggerModelDSL
- Defined in:
- lib/swagger/docs/dsl.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #description(description) ⇒ Object
- #properties ⇒ Object
- #property(name, type, required, description = nil, hash = {}) ⇒ Object
- #required ⇒ Object
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
67 68 69 |
# File 'lib/swagger/docs/dsl.rb', line 67 def id @id end |
Class Method Details
.call(model_name, caller, &block) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/swagger/docs/dsl.rb', line 70 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
91 92 93 |
# File 'lib/swagger/docs/dsl.rb', line 91 def description(description) @description = description end |
#properties ⇒ Object
83 84 85 |
# File 'lib/swagger/docs/dsl.rb', line 83 def properties @properties ||= {} end |
#property(name, type, required, description = nil, hash = {}) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/swagger/docs/dsl.rb', line 95 def property(name, type, required, description = nil, hash={}) properties[name] = { type: type, description: description, }.merge!(hash) self.required << name if required == :required end |
#required ⇒ Object
87 88 89 |
# File 'lib/swagger/docs/dsl.rb', line 87 def required @required ||= [] end |