Class: SwaggerYard::ApiDeclaration
- Inherits:
-
Object
- Object
- SwaggerYard::ApiDeclaration
- Defined in:
- lib/swagger_yard/api_declaration.rb
Instance Attribute Summary collapse
-
#apis ⇒ Object
readonly
Returns the value of attribute apis.
-
#authorizations ⇒ Object
readonly
Returns the value of attribute authorizations.
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
-
#description ⇒ Object
Returns the value of attribute description.
-
#resource ⇒ Object
Returns the value of attribute resource.
Class Method Summary collapse
Instance Method Summary collapse
- #add_api(yard_object) ⇒ Object
- #add_info(yard_object) ⇒ Object
- #add_yard_object(yard_object) ⇒ Object
- #apis_hash ⇒ Object
-
#initialize ⇒ ApiDeclaration
constructor
A new instance of ApiDeclaration.
- #to_tag ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize ⇒ ApiDeclaration
Returns a new instance of ApiDeclaration.
10 11 12 13 14 |
# File 'lib/swagger_yard/api_declaration.rb', line 10 def initialize @resource = nil @apis = {} = {} end |
Instance Attribute Details
#apis ⇒ Object (readonly)
Returns the value of attribute apis.
4 5 6 |
# File 'lib/swagger_yard/api_declaration.rb', line 4 def apis @apis end |
#authorizations ⇒ Object (readonly)
Returns the value of attribute authorizations.
4 5 6 |
# File 'lib/swagger_yard/api_declaration.rb', line 4 def end |
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
4 5 6 |
# File 'lib/swagger_yard/api_declaration.rb', line 4 def class_name @class_name end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/swagger_yard/api_declaration.rb', line 3 def description @description end |
#resource ⇒ Object
Returns the value of attribute resource.
3 4 5 |
# File 'lib/swagger_yard/api_declaration.rb', line 3 def resource @resource end |
Class Method Details
.from_yard_object(yard_object) ⇒ Object
6 7 8 |
# File 'lib/swagger_yard/api_declaration.rb', line 6 def self.from_yard_object(yard_object) new.add_yard_object(yard_object) end |
Instance Method Details
#add_api(yard_object) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/swagger_yard/api_declaration.rb', line 54 def add_api(yard_object) path = Api.path_from_yard_object(yard_object) return if path.nil? api = (apis[path] ||= Api.from_yard_object(yard_object, self)) api.add_operation(yard_object) end |
#add_info(yard_object) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/swagger_yard/api_declaration.rb', line 35 def add_info(yard_object) @description = yard_object.docstring @class_name = yard_object.path if tag = yard_object..detect {|t| t.tag_name == "resource"} @resource = tag.text end if tag = yard_object..detect {|t| t.tag_name == "resource_path"} log.warn "DEPRECATED: @resource_path tag is obsolete." end # we only have api_key auth, the value for now is always empty array = Hash[yard_object.. select {|t| t.tag_name == "authorize_with"}. map(&:text).uniq. map {|k| [k, []]}] end |
#add_yard_object(yard_object) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/swagger_yard/api_declaration.rb', line 20 def add_yard_object(yard_object) case yard_object.type when :class # controller add_info(yard_object) if valid? yard_object.children.each do |child_object| add_yard_object(child_object) end end when :method # actions add_api(yard_object) end self end |
#apis_hash ⇒ Object
63 64 65 |
# File 'lib/swagger_yard/api_declaration.rb', line 63 def apis_hash Hash[apis.map {|path, api| [path, api.operations_hash]}] end |
#to_tag ⇒ Object
67 68 69 70 |
# File 'lib/swagger_yard/api_declaration.rb', line 67 def to_tag { "name" => resource, "description" => description } end |
#valid? ⇒ Boolean
16 17 18 |
# File 'lib/swagger_yard/api_declaration.rb', line 16 def valid? !@resource.nil? end |