Class: SwaggerYard::ApiGroup
- Inherits:
-
Object
- Object
- SwaggerYard::ApiGroup
- Defined in:
- lib/swagger_yard/api_group.rb
Instance Attribute Summary collapse
-
#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.
-
#path_items ⇒ Object
readonly
Returns the value of attribute path_items.
-
#resource ⇒ Object
Returns the value of attribute resource.
Class Method Summary collapse
Instance Method Summary collapse
- #add_info(yard_object) ⇒ Object
- #add_path_item(yard_object) ⇒ Object
- #add_yard_object(yard_object) ⇒ Object
-
#initialize ⇒ ApiGroup
constructor
A new instance of ApiGroup.
- #path_from_yard_object(yard_object) ⇒ Object
- #paths ⇒ Object
- #tag ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize ⇒ ApiGroup
Returns a new instance of ApiGroup.
33 34 35 36 37 |
# File 'lib/swagger_yard/api_group.rb', line 33 def initialize @resource = nil @path_items = {} = {} end |
Instance Attribute Details
#authorizations ⇒ Object (readonly)
Returns the value of attribute authorizations.
27 28 29 |
# File 'lib/swagger_yard/api_group.rb', line 27 def end |
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
27 28 29 |
# File 'lib/swagger_yard/api_group.rb', line 27 def class_name @class_name end |
#description ⇒ Object
Returns the value of attribute description.
26 27 28 |
# File 'lib/swagger_yard/api_group.rb', line 26 def description @description end |
#path_items ⇒ Object (readonly)
Returns the value of attribute path_items.
27 28 29 |
# File 'lib/swagger_yard/api_group.rb', line 27 def path_items @path_items end |
#resource ⇒ Object
Returns the value of attribute resource.
26 27 28 |
# File 'lib/swagger_yard/api_group.rb', line 26 def resource @resource end |
Class Method Details
.from_yard_object(yard_object) ⇒ Object
29 30 31 |
# File 'lib/swagger_yard/api_group.rb', line 29 def self.from_yard_object(yard_object) new.add_yard_object(yard_object) end |
Instance Method Details
#add_info(yard_object) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# 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..detect {|t| t.tag_name == "resource"} @resource = tag.text 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_path_item(yard_object) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# 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) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/swagger_yard/api_group.rb', line 91 def path_from_yard_object(yard_object) if tag = yard_object..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. nil end end end |
#paths ⇒ Object
43 44 45 |
# File 'lib/swagger_yard/api_group.rb', line 43 def paths Paths.new(path_items) end |
#tag ⇒ Object
47 48 49 |
# File 'lib/swagger_yard/api_group.rb', line 47 def tag @tag ||= Tag.new(resource, description) end |
#valid? ⇒ Boolean
39 40 41 |
# File 'lib/swagger_yard/api_group.rb', line 39 def valid? !@resource.nil? end |