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 7 def initialize(global_info = nil, version: nil) @data = {} @global_info = global_info @version = version return unless @global_info.nil? # this *is* the global info version_with %i[header params] consumes 'json', 'x-www-form-urlencoded' produces 'json' end
Public Instance Methods
base_params(type = Attributor::Struct, **opts, &block)
click to toggle source
# File lib/praxis/api_general_info.rb, line 146 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 113 def base_path(val = nil) return set(:base_path, val) if val 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 => version.to_s) 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 130 def consumes(*vals) if vals.empty? get(:consumes) else set(:consumes, vals) end end
describe()
click to toggle source
# File lib/praxis/api_general_info.rb, line 154 def describe hash = { schema_version: '1.0' } %i[name title description base_path version_with endpoint consumes produces].each do |attr| val = __send__(attr) hash[attr] = val unless val.nil? end hash[:base_params] = base_params.describe[:type][:attributes] if base_params hash end
description(val = nil)
click to toggle source
# File lib/praxis/api_general_info.rb, line 68 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 101 def documentation_url(val = nil) if val.nil? get(:documentation_url) elsif @global_info.nil? set(:documentation_url, val) # this *is* the global info 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 #{version}" end end
endpoint(val = nil)
click to toggle source
# File lib/praxis/api_general_info.rb, line 89 def endpoint(val = nil) if val.nil? get(:endpoint) elsif @global_info.nil? set(:endpoint, val) # this *is* the global info 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 #{version}" end end
get(key)
click to toggle source
# File lib/praxis/api_general_info.rb, line 33 def get(key) return @data[key] if @data.key?(key) return @global_info.get(key) if @global_info nil end
logo_url(val = nil)
click to toggle source
# File lib/praxis/api_general_info.rb, line 60 def logo_url(val = nil) if val.nil? get(:logo_url) else set(:logo_url, val) end end
method_missing(name, val = nil)
click to toggle source
Allow any custom method to get/set any value
# File lib/praxis/api_general_info.rb, line 21 def method_missing(name, val = nil) if val.nil? get(name) else set(name, val) end end
name(val = nil)
click to toggle source
# File lib/praxis/api_general_info.rb, line 44 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 138 def produces(*vals) if vals.empty? get(:produces) else set(:produces, vals) end end
respond_to_missing?(*)
click to toggle source
# File lib/praxis/api_general_info.rb, line 29 def respond_to_missing?(*) true end
set(key, val)
click to toggle source
# File lib/praxis/api_general_info.rb, line 40 def set(key, val) @data[key] = val end
title(val = nil)
click to toggle source
# File lib/praxis/api_general_info.rb, line 52 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 76 def version_with(val = nil) if val.nil? get(:version_with) elsif @global_info.nil? Application.instance.versioning_scheme = val set(:version_with, val) # this *is* the global info 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 #{version}" end end