class CabbageDoc::Configuration

Constants

ATTRIBUTES
CALLABLE_ATTRIBUTES
DEFAULTS
OPTIONAL_ATTRIBUTES
REQUIRED_ATTRIBUTES

Public Class Methods

format_example(example, action, auth) click to toggle source
# File lib/cabbage_doc/configuration.rb, line 6
def format_example(example, action, auth)
  cmd = ["$", "curl"]

  if auth.type == :basic
    cmd << "-u \"user:pass\""
  elsif auth.token
    cmd << "-H \"Authorization: #{auth.type.to_s.capitalize} token\""
  end

  if action.method == "GET"
    path = [action.path, example.to_query].join("?")
  else
    cmd << "-X #{action.method}"

    example.params.each do |k, v|
      cmd << "-d \"#{k}=#{v}\""
    end

    path = action.path
  end

  cmd << "\"#{[auth.uri, path].join}\""

  cmd.join(' ')
end
new() click to toggle source
# File lib/cabbage_doc/configuration.rb, line 66
def initialize
  DEFAULTS.each do |attr, value|
    send(:"#{attr}=", value)
  end
end

Public Instance Methods

validate!() click to toggle source
# File lib/cabbage_doc/configuration.rb, line 72
def validate!
  validate_required!
  validate_callable!
  validate_root!
  validate_visibility!
end

Private Instance Methods

validate_callable!() click to toggle source
# File lib/cabbage_doc/configuration.rb, line 87
def validate_callable!
  CALLABLE_ATTRIBUTES.each do |attr|
    if (value = send(attr)) && !value.respond_to?(:call)
      raise ArgumentError, "#{attr} is not callable"
    end
  end
end
validate_required!() click to toggle source
# File lib/cabbage_doc/configuration.rb, line 81
def validate_required!
  REQUIRED_ATTRIBUTES.each do |attr|
    raise ArgumentError, "#{attr} is required" unless send(attr)
  end
end
validate_root!() click to toggle source
# File lib/cabbage_doc/configuration.rb, line 95
def validate_root!
  raise ArgumentError, "#{root} directory doesn't exist" unless Dir.exists?(root)
end
validate_visibility!() click to toggle source
# File lib/cabbage_doc/configuration.rb, line 99
def validate_visibility!
  self.visibility = Array(visibility)
  self.visibility.each do |v|
    valid = VISIBILITY.include?(v) || tags.include?(v)
    raise ArgumentError, "#{v} invalid visibility" unless valid
  end
end