Class: RestApiDoc::ResourceDoc
- Inherits:
-
Object
- Object
- RestApiDoc::ResourceDoc
- Defined in:
- lib/restapi_doc/resource_doc.rb
Instance Attribute Summary collapse
-
#class_block ⇒ Object
readonly
Returns the value of attribute class_block.
-
#controller_name ⇒ Object
readonly
Returns the value of attribute controller_name.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#function_blocks ⇒ Object
readonly
Returns the value of attribute function_blocks.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#resource_header ⇒ Object
readonly
Returns the value of attribute resource_header.
-
#resource_location ⇒ Object
readonly
Returns the value of attribute resource_location.
-
#resource_methods ⇒ Object
readonly
Returns the value of attribute resource_methods.
Class Method Summary collapse
-
.parse_controller_doc(name, lines) ⇒ Object
This method parses the doc.
Instance Method Summary collapse
-
#initialize(name, action_methods, controller_location, options = {}) ⇒ ResourceDoc
constructor
Initializes ResourceDoc.
-
#parse_apidoc ⇒ Object
parse the controller.
Constructor Details
#initialize(name, action_methods, controller_location, options = {}) ⇒ ResourceDoc
Initializes ResourceDoc.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/restapi_doc/resource_doc.rb', line 12 def initialize(name, action_methods, controller_location, = {}) @name = name @class_block = nil @function_blocks = [] @resource_methods = action_methods @resource_header = "" @standard_methods = [:standard_methods] || [:put, :post, :get, :delete] @resource_location = resource_location @controller_location = controller_location @description = nil @controller_name = File.basename(controller_location) end |
Instance Attribute Details
#class_block ⇒ Object (readonly)
Returns the value of attribute class_block.
9 10 11 |
# File 'lib/restapi_doc/resource_doc.rb', line 9 def class_block @class_block end |
#controller_name ⇒ Object (readonly)
Returns the value of attribute controller_name.
9 10 11 |
# File 'lib/restapi_doc/resource_doc.rb', line 9 def controller_name @controller_name end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
9 10 11 |
# File 'lib/restapi_doc/resource_doc.rb', line 9 def description @description end |
#function_blocks ⇒ Object (readonly)
Returns the value of attribute function_blocks.
9 10 11 |
# File 'lib/restapi_doc/resource_doc.rb', line 9 def function_blocks @function_blocks end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/restapi_doc/resource_doc.rb', line 9 def name @name end |
#resource_header ⇒ Object (readonly)
Returns the value of attribute resource_header.
9 10 11 |
# File 'lib/restapi_doc/resource_doc.rb', line 9 def resource_header @resource_header end |
#resource_location ⇒ Object (readonly)
Returns the value of attribute resource_location.
9 10 11 |
# File 'lib/restapi_doc/resource_doc.rb', line 9 def resource_location @resource_location end |
#resource_methods ⇒ Object (readonly)
Returns the value of attribute resource_methods.
9 10 11 |
# File 'lib/restapi_doc/resource_doc.rb', line 9 def resource_methods @resource_methods end |
Class Method Details
.parse_controller_doc(name, lines) ⇒ Object
This method parses the doc
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/restapi_doc/resource_doc.rb', line 44 def self.parse_controller_doc(name, lines) current_api_block = nil current_scope = :none in_class = false class_block = nil function_blocks = [] order = 1 lines.each_with_index do |line, line_no| line.gsub!(/^ *#/, '') # strip the starting '#' on the line case line when /=begin apidoc/ # if we get apidoc tag inside class definition, then they are for a method current_scope = !in_class ? :class : :function current_api_block = MethodDoc.new(name, current_scope, order) when /=end/ if current_api_block.nil? raise ParsingException, "#{line_no} - No starttag for '=end' found" end when /class/ # keep track of whether a resource or an api is being annotated in_class = true if !current_api_block.nil? case current_scope when :class class_block = current_api_block when :function function_blocks << current_api_block else raise ParsingException, "logic error: unknown current scope #{current_scope}" end current_api_block = nil current_scope = :none order += 1 end when /def / if !current_api_block.nil? current_api_block.defname = line.gsub('def ', '').strip case current_scope when :class class_block = current_api_block when :function function_blocks << current_api_block else raise ParsingException, "logic error: unknown current scope #{current_scope}" end current_api_block = nil current_scope = :none order += 1 end else if current_api_block # process lines only if they are apidoc comments current_scope = current_api_block.process_line(line, current_scope) end end end [class_block, function_blocks] end |
Instance Method Details
#parse_apidoc ⇒ Object
parse the controller
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/restapi_doc/resource_doc.rb', line 26 def parse_apidoc lines = IO.readlines(@controller_location) begin @class_block, @function_blocks = ResourceDoc.parse_controller_doc(@name, lines) rescue ParsingException => ex puts "error #{ex} while parsing #{@controller_location}" exit end if !@class_block.nil? @description = @class_block.content end @resource_methods.each do | req_m | req_m << @function_blocks.select{|f| f.defname == req_m[0]}.first end end |