class Praxis::ApiGeneralInfo

Attributes

version[R]

Public Class Methods

new(global_info=nil, version: nil) click to toggle source
# File lib/praxis/api_general_info.rb, line 6
def initialize(global_info=nil, version: nil)
  @data = Hash.new
  @global_info = global_info
  @version = version

  if @global_info.nil? # this *is* the global info
    version_with [:header, :params]
    consumes 'json', 'x-www-form-urlencoded'
    produces 'json'
  end
end

Public Instance Methods

base_params(type=Attributor::Struct, **opts, &block) click to toggle source
# File lib/praxis/api_general_info.rb, line 132
def base_params(type=Attributor::Struct, **opts, &block)
  if !block && type == Attributor::Struct
    get(:base_params)
  else
    set(:base_params, Attributor::Attribute.new(type, opts, &block) )
  end
end
base_path(val=nil) click to toggle source
# File lib/praxis/api_general_info.rb, line 95
def base_path(val=nil)
  if val
    return set(:base_path, val)
  end

  if @global_info # this is for a specific version
    global_path = @global_info.base_path
    if version_with == :path
      global_pattern = Mustermann.new(global_path)
      global_path = global_pattern.expand(Request::API_VERSION_PARAM_NAME => self.version)
    end

    version_path = @data.fetch(:base_path,'')
    "#{global_path}#{version_path}"
  else
    @data.fetch(:base_path,'')
  end
end
consumes(*vals) click to toggle source
# File lib/praxis/api_general_info.rb, line 114
def consumes(*vals)
  if vals.empty?
    return get(:consumes)
  else
    return set(:consumes, vals)
  end
end
describe() click to toggle source
# File lib/praxis/api_general_info.rb, line 140
def describe
  hash = { schema_version: "1.0".freeze }
  [:name, :title, :description, :base_path, :version_with, :endpoint, :consumes, :produces].each do |attr|
    val = self.__send__(attr)
    hash[attr] = val unless val.nil?
  end
  if base_params
    hash[:base_params] = base_params.describe[:type][:attributes]
  end
  hash
end
description(val=nil) click to toggle source
# File lib/praxis/api_general_info.rb, line 44
def description(val=nil)
  if val.nil?
    get(:description)
  else
    set(:description, val)
  end
end
documentation_url(val=nil) click to toggle source
# File lib/praxis/api_general_info.rb, line 81
def documentation_url(val=nil)
  if val.nil?
    get(:documentation_url)
  else
    if @global_info.nil? # this *is* the global info
      set(:documentation_url, val)
    else
      raise "Use of documentation_url is only allowed in the global part of " \
        "the API definition (but you are attempting to use it in the API " \
        "definition of version #{self.version}"
    end
  end
end
endpoint(val=nil) click to toggle source
# File lib/praxis/api_general_info.rb, line 67
def endpoint(val=nil)
  if val.nil?
    get(:endpoint)
  else
    if @global_info.nil? # this *is* the global info
      set(:endpoint, val)
    else
      raise "Use of endpoint is only allowed in the global part of " \
        "the API definition (but you are attempting to use it in the API " \
        "definition of version #{self.version}"
    end
  end
end
get(k) click to toggle source
# File lib/praxis/api_general_info.rb, line 18
def get(k)
  return @data[k] if @data.key?(k)
  return @global_info.get(k) if @global_info
  nil
end
name(val=nil) click to toggle source
# File lib/praxis/api_general_info.rb, line 28
def name(val=nil)
  if val.nil?
    get(:name)
  else
    set(:name, val)
  end
end
produces(*vals) click to toggle source
# File lib/praxis/api_general_info.rb, line 123
def produces(*vals)
  if vals.empty?
    return get(:produces)
  else
    return set(:produces, vals)
  end
end
set(k, v) click to toggle source
# File lib/praxis/api_general_info.rb, line 24
def set(k, v)
  @data[k] = v
end
title(val=nil) click to toggle source
# File lib/praxis/api_general_info.rb, line 36
def title(val=nil)
  if val.nil?
    get(:title)
  else
    set(:title, val)
  end
end
version_with(val=nil) click to toggle source
# File lib/praxis/api_general_info.rb, line 52
def version_with(val=nil)
  if val.nil?
    get(:version_with)
  else
    if @global_info.nil? # this *is* the global info
      Application.instance.versioning_scheme = val
      set(:version_with, val)
    else
      raise "Use of version_with is only allowed in the global part of " \
        "the API definition (but you are attempting to use it in the API " \
        "definition of version #{self.version}"
    end
  end
end