Class: Swagger::Blocks::Node
- Inherits:
-
Object
- Object
- Swagger::Blocks::Node
show all
- Defined in:
- lib/swagger/blocks.rb
Overview
Base node for representing every object in the Swagger DSL.
Direct Known Subclasses
ApiAuthorizationNode, ApiAuthorizationScopeNode, ApiAuthorizationsNode, ApiDeclarationNode, ApiNode, AuthorizationCodeNode, GrantTypesNode, ImplicitNode, InfoNode, ItemsNode, LoginEndpointNode, ModelNode, ModelsNode, OperationNode, ParameterNode, PropertiesNode, PropertyNode, ResourceListingAuthorizationNode, ResourceListingAuthorizationsNode, ResourceListingNode, ResourceNode, ScopeNode, TokenEndpointNode, TokenRequestEndpointNode
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
129
130
131
|
# File 'lib/swagger/blocks.rb', line 129
def name
@name
end
|
Class Method Details
.call(options = {}, &block) ⇒ Object
131
132
133
134
135
136
137
|
# File 'lib/swagger/blocks.rb', line 131
def self.call(options = {}, &block)
instance = new
instance.name = options[:name] if options[:name]
instance.instance_eval(&block)
instance
end
|
Instance Method Details
#as_json ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/swagger/blocks.rb', line 139
def as_json
result = {}
self.data.each do |key, value|
if value.is_a?(Node)
result[key] = value.as_json
elsif value.is_a?(Array)
result[key] = []
value.each { |v| result[key] << (v.respond_to?(:as_json) ? v.as_json : v) }
else
result[key] = value
end
end
return result if !name
{name => result}
end
|
#data ⇒ Object
156
157
158
|
# File 'lib/swagger/blocks.rb', line 156
def data
@data ||= {}
end
|
#key(key, value) ⇒ Object
160
161
162
|
# File 'lib/swagger/blocks.rb', line 160
def key(key, value)
self.data[key] = value
end
|