class Goodall
This sucks. It needs love from someone who knows xml. That’s not me.
Constants
- VERSION
Public Class Methods
Enable Goodall
, which is the default by default.
# File lib/goodall.rb, line 47 def self.disable self.enabled = false end
Document a request.
-
:method
- a symbol of the verb: :get, :post, :put, :delete, :patch -
:path
- a string of the path (URL/URI) of the request -
:payload
- the parameters sent, e.g. post body. Usually a hash.
# File lib/goodall.rb, line 81 def self.document_request(method, path, payload=nil) return unless should_document? str = "#{method.to_s.upcase}: #{path}" if payload && payload.to_s.size > 0 str << "\n" + current_handler.parse_payload(payload) end str << "\n" writer.write(str) end
Document a response.
-
+:payload - the data returned from the request, e.g. response.body. ‘payload` will be run through the current handler and be pretty-printed to the output file.
# File lib/goodall.rb, line 98 def self.document_response(payload, status=nil) return unless should_document? if payload payload = current_handler.parse_payload(payload) end str = if status "RESPONSE: #{status}" else "RESPONSE:" end str << "\n#{payload}\n" writer.write(str) end
Enable Goodall
, which is disabled by default.
# File lib/goodall.rb, line 42 def self.enable self.enabled=true end
Is Goodall
logging enabled?
# File lib/goodall.rb, line 27 def self.enabled @@enabled end
Explicity set the enabled state, true or false
# File lib/goodall.rb, line 37 def self.enabled=(val) @@enabled=!!val end
alias unreliable on class methods, use this instead.
# File lib/goodall.rb, line 32 def self.enabled? enabled end
Get the current documentation output path
# File lib/goodall.rb, line 17 def self.output_path @@output_path end
Set the current documentation output path
# File lib/goodall.rb, line 22 def self.output_path=(val) @@output_path = val end
When writing a custom hander, it must register itself with Goodall
using this method.
-
:payload_type
- The name of the kind of content that this handler will be processing, e.g. JSON, XML, HTML etc. -
:handler_class
- The class of the handler itself (not the class name).
# File lib/goodall.rb, line 126 def self.register_handler(payload_type, handler_class) @@registered_handlers[payload_type.to_sym] = handler_class end
returns an array of arrays of the currently registered handlers.
- [ :identifier, class ], [ :identifier, class
-
]
# File lib/goodall.rb, line 147 def self.registered_handlers @@registered_handlers.map{|k,v| [k,v]} end
Set the currently active handler. By default, if only one handler is registered then it will be made active by default. If you hanve multiple handlers registered and wish to switch between them, use this.
-
:handler_name
-Handler
name as a symbol, e.g. :json, :xml.
# File lib/goodall.rb, line 135 def self.set_handler(handler_name) handler_name = handler_name.to_sym if handler_class = @@registered_handlers[handler_name] @current_handler = handler_class.new else raise HandlerNotRegisteredError, "No handler registered for for #{handler_name}" end end
Is goodall enabled and are NOT in skipping mode?
# File lib/goodall.rb, line 152 def self.should_document? enabled? && !skipping? end
set the skipping value explicity
# File lib/goodall.rb, line 67 def self.skipping=(val) @@skipping=!!val end
Flag to denote that documenting temporarily disabled?
# File lib/goodall.rb, line 52 def self.skipping? @@skipping end
Disable the temporarily disable documenting flag
# File lib/goodall.rb, line 62 def self.skipping_off! self.skipping = false end
Enable the temporarily disable documenting flag
# File lib/goodall.rb, line 57 def self.skipping_on! self.skipping = true end
write to the currently open output file
# File lib/goodall.rb, line 72 def self.write(str) writer.write(str) if enabled? end
Private Class Methods
# File lib/goodall.rb, line 158 def self.current_handler @current_handler ||= if default_handler = @@registered_handlers.first default_handler[1].new else raise( Goodall::NoHandlersRegisteredError, "There are no handlers registered, please require at least one." ) end end
# File lib/goodall.rb, line 169 def self.writer @writer ||= Goodall::Writer.new(@@output_path) end