class SwaggerYard::ApiGroup
Attributes
class_name[R]
description[RW]
path_items[R]
resource[RW]
Public Class Methods
from_yard_object(yard_object)
click to toggle source
# File lib/swagger_yard/api_group.rb, line 29 def self.from_yard_object(yard_object) new.add_yard_object(yard_object) end
new()
click to toggle source
# File lib/swagger_yard/api_group.rb, line 33 def initialize @resource = nil @path_items = {} @authorizations = {} end
Public Instance Methods
add_info(yard_object)
click to toggle source
# File lib/swagger_yard/api_group.rb, line 66 def add_info(yard_object) @description = yard_object.docstring @class_name = yard_object.path if tag = yard_object.tags.detect {|t| t.tag_name == "resource"} @resource = tag.text end # we only have api_key auth, the value for now is always empty array @authorizations = Hash[yard_object.tags. select {|t| t.tag_name == "authorize_with"}. map(&:text).uniq. map {|k| [k, []]}] end
add_path_item(yard_object)
click to toggle source
# File lib/swagger_yard/api_group.rb, line 81 def add_path_item(yard_object) path = path_from_yard_object(yard_object) return if path.nil? path_item = (path_items[path] ||= PathItem.new(self)) path_item.add_operation(yard_object) path end
add_yard_object(yard_object)
click to toggle source
# File lib/swagger_yard/api_group.rb, line 51 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_path_item(yard_object) end self end
path_from_yard_object(yard_object)
click to toggle source
# File lib/swagger_yard/api_group.rb, line 91 def path_from_yard_object(yard_object) if tag = yard_object.tags.detect {|t| t.tag_name == "path"} tag.text elsif fn = SwaggerYard.config.path_discovery_function begin method, path = fn[yard_object] yard_object.add_tag YARD::Tags::Tag.new("path", path, [method]) if path path rescue => e SwaggerYard.log.warn e.message nil end end end
paths()
click to toggle source
# File lib/swagger_yard/api_group.rb, line 43 def paths Paths.new(path_items) end
tag()
click to toggle source
# File lib/swagger_yard/api_group.rb, line 47 def tag @tag ||= Tag.new(resource, description) end
valid?()
click to toggle source
# File lib/swagger_yard/api_group.rb, line 39 def valid? !@resource.nil? end