module Grape::DSL::Settings

def get_or_set(setting, key, value)

def get_or_set(setting, key, value)
  return setting[key] if value.nil?
  setting[key] = value
end

def global_setting(key, value = nil)

def global_setting(key, value = nil)
  get_or_set(inheritable_setting.global, key, value)
end

def inheritable_setting

nested scopes but not shared across siblings.
Fetch our current inheritable settings, which are inherited by
def inheritable_setting
  return @inheritable_setting if @inheritable_setting
  @inheritable_setting = Grape::Util::InheritableSetting.new
  @inheritable_setting.inherit_from top_level_setting
  @inheritable_setting
end

def namespace_setting(key, value = nil)

def namespace_setting(key, value = nil)
  get_or_set(inheritable_setting.namespace, key, value)
end

def route_setting(key, value = nil)

def route_setting(key, value = nil)
  get_or_set(inheritable_setting.route, key, value)
end

def top_level_setting

Fetch our top-level settings, which apply to all endpoints in the API.
def top_level_setting
  return @top_level_setting if @top_level_setting
  @top_level_setting = Grape::Util::InheritableSetting.new
  # Doesn't try to inherit settings from +Grape::API::Instance+ which also responds to
  # +inheritable_setting+, however, it doesn't contain any user-defined settings.
  # Otherwise, it would lead to an extra instance of +Grape::Util::InheritableSetting+
  # in the chain for every endpoint.
  @top_level_setting.inherit_from superclass.inheritable_setting if defined?(superclass) && superclass.respond_to?(:inheritable_setting) && superclass != Grape::API::Instance
  @top_level_setting
end

def within_namespace

to a new copy (see #namespace_start).
Execute the block within a context where our inheritable settings are forked
def within_namespace
  new_inheritable_settings = Grape::Util::InheritableSetting.new
  new_inheritable_settings.inherit_from inheritable_setting
  @inheritable_setting = new_inheritable_settings
  result = yield
  inheritable_setting.route_end
  @inheritable_setting = inheritable_setting.parent
  reset_validations!
  result
end