Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

documentation utilities

  • Loading branch information...
commit b311b0e2499f3f9e2b2cbf8b1f03195dfffaff81 1 parent 7446d4a
Steven Davidovitz steved555 authored
Showing with 84 additions and 0 deletions.
  1. +68 −0 util/resource_handler.rb
  2. +16 −0 util/verb_handler.rb
68 util/resource_handler.rb
View
@@ -0,0 +1,68 @@
+require 'zendesk_api'
+
+class ResourceHandler < YARD::Handlers::Ruby::Base
+ handles method_call(:has), method_call(:has_many)
+
+ def process
+ many = statement.jump(:ident).source == "has_many"
+
+ klass = get_klass(statement)
+
+ if klass
+ begin
+ klass = klass.split("::").inject(ZendeskAPI) do |p,k|
+ p.const_get(k)
+ end
+ rescue NameError
+ parent = ZendeskAPI.const_get(namespace.to_s.split('::').last)
+ klass = parent.const_get(klass)
+ end
+
+ name = statement.parameters.first.jump(:ident).source
+ else
+ klass = statement.parameters.first.source
+
+ begin
+ klass = ZendeskAPI.const_get(klass)
+ rescue NameError
+ parent = ZendeskAPI.const_get(namespace.to_s.split('::').last)
+ klass = parent.const_get(klass)
+ end
+
+ name = many ? klass.resource_name : klass.singular_resource_name
+ end
+
+ reader = YARD::CodeObjects::MethodObject.new(namespace, name)
+ register(reader)
+ reader.dynamic = true
+ reader.docstring.add_tag(YARD::Tags::Tag.new(:return, "The associated object", klass.name))
+
+ if many
+ reader.signature = "def #{name}=(options = {})"
+ reader.parameters = [['options', {}]]
+ reader.docstring.add_tag(YARD::Tags::Tag.new(:param, "Options to pass to the collection object", "Hash", "options"))
+ end
+
+ writer = YARD::CodeObjects::MethodObject.new(namespace, "#{name}=")
+ register(writer)
+ writer.signature = "def #{name}=(value)"
+ writer.parameters = [['value', nil]]
+ writer.dynamic = true
+ writer.docstring.add_tag(YARD::Tags::Tag.new(:return, "The associated object", klass.name))
+ writer.docstring.add_tag(YARD::Tags::Tag.new(:param, "The associated object or its attributes", "Hash or #{klass.name}", "value"))
+ end
+
+ def get_klass(statement)
+ statement.traverse do |node|
+ if node.type == :assoc && node.jump(:kw).source == "class"
+ classes = node.traverse do |value|
+ if value.type == :const_path_ref || value.type == :var_ref
+ return value.source
+ end
+ end
+ end
+ end
+
+ nil
+ end
+end
16 util/verb_handler.rb
View
@@ -0,0 +1,16 @@
+class VerbHandler < YARD::Handlers::Ruby::Base
+ handles method_call(:put), method_call(:post), method_call(:get)
+
+ def process
+ name = statement.parameters.first.jump(:ident).source
+
+ verb = YARD::CodeObjects::MethodObject.new(namespace, name)
+ register(verb)
+ verb.dynamic = true
+ verb.docstring.add_tag(YARD::Tags::Tag.new(:return, "Success of this call", "Boolean"))
+
+ verb.signature = "def #{name}=(options = {})"
+ verb.parameters = [['options', {}]]
+ verb.docstring.add_tag(YARD::Tags::Tag.new(:param, "Options to pass to the request", "Hash", "options"))
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.