module SkinnyControllers::Lookup::EnsureExistence

NOTE: This is a lot of hackery.

Please Explicitly Define things if you are able

Public Instance Methods

ensure_namespace!(namespace) click to toggle source

@return [Module] namespace

# File lib/skinny_controllers/lookup/ensure_existence.rb, line 9
def ensure_namespace!(namespace)
  klass = namespace_lookup(namespace)
  klass || Namespace.create_namespace(namespace)
end
ensure_operation_class!(qualified_name) click to toggle source
# File lib/skinny_controllers/lookup/ensure_existence.rb, line 14
def ensure_operation_class!(qualified_name)
  klass = operation_lookup(qualified_name)
  klass || use_defailt_operation(qualified_name)
end
ensure_policy_class!(qualified_name) click to toggle source
# File lib/skinny_controllers/lookup/ensure_existence.rb, line 19
def ensure_policy_class!(qualified_name)
  klass = policy_lookup(qualified_name)
  klass || Lookup::Policy.define_policy_class(qualified_name)
end
use_defailt_operation(qualified_name) click to toggle source

This assumes the namespace already exists This is only to be used if there does not exist operation that goes by the name defined by qualified_name (hence the warn log at the top)

@param [String] qualified_name the name of the class to create @example 'Api::V2::PostOperations::Create'

@return [Class] a duplicate of the default operation

# File lib/skinny_controllers/lookup/ensure_existence.rb, line 33
def use_defailt_operation(qualified_name)
  SkinnyControllers.logger.warn("#{qualified_name} not found. Creating default...")

  parts = qualified_name.split('::')
  class_name = parts.pop
  namespace = parts.join('::').safe_constantize

  namespace.const_set(
    class_name,
    SkinnyControllers::Operation::Default.dup
  )
end