class Goodall

This sucks. It needs love from someone who knows xml. That’s not me.

Constants

VERSION

Public Class Methods

disable() click to toggle source

Enable Goodall, which is the default by default.

# File lib/goodall.rb, line 47
def self.disable
  self.enabled = false
end
document_request(method, path, payload=nil) click to toggle source

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_response(payload, status=nil) click to toggle source

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() click to toggle source

Enable Goodall, which is disabled by default.

# File lib/goodall.rb, line 42
def self.enable
  self.enabled=true
end
enabled() click to toggle source

Is Goodall logging enabled?

# File lib/goodall.rb, line 27
def self.enabled
  @@enabled
end
enabled=(val) click to toggle source

Explicity set the enabled state, true or false

# File lib/goodall.rb, line 37
def self.enabled=(val)
  @@enabled=!!val
end
enabled?() click to toggle source

alias unreliable on class methods, use this instead.

# File lib/goodall.rb, line 32
def self.enabled?
  enabled
end
output_path() click to toggle source

Get the current documentation output path

# File lib/goodall.rb, line 17
def self.output_path
  @@output_path
end
output_path=(val) click to toggle source

Set the current documentation output path

# File lib/goodall.rb, line 22
def self.output_path=(val)
  @@output_path = val
end
register_handler(payload_type, handler_class) click to toggle source

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
registered_handlers() click to toggle source

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_handler(handler_name) click to toggle source

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
should_document?() click to toggle source

Is goodall enabled and are NOT in skipping mode?

# File lib/goodall.rb, line 152
def self.should_document?
  enabled? && !skipping?
end
skipping=(val) click to toggle source

set the skipping value explicity

# File lib/goodall.rb, line 67
def self.skipping=(val)
  @@skipping=!!val
end
skipping?() click to toggle source

Flag to denote that documenting temporarily disabled?

# File lib/goodall.rb, line 52
def self.skipping?
  @@skipping
end
skipping_off!() click to toggle source

Disable the temporarily disable documenting flag

# File lib/goodall.rb, line 62
def self.skipping_off!
  self.skipping = false
end
skipping_on!() click to toggle source

Enable the temporarily disable documenting flag

# File lib/goodall.rb, line 57
def self.skipping_on!
  self.skipping = true
end
write(str) click to toggle source

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

current_handler() click to toggle source
# 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
writer() click to toggle source
# File lib/goodall.rb, line 169
def self.writer
  @writer ||= Goodall::Writer.new(@@output_path)
end