class Wallaby::Mode

This is the interface that all ORM modes should inherit from and implement.

Public Class Methods

default_authorization_provider() click to toggle source

@see Wallaby::ModelPaginationProvider @return [Class] pagination provider for the mode @since wallaby-5.2.0

# File lib/interfaces/wallaby/mode.rb, line 35
def default_authorization_provider
  check_and_constantize __callee__
end
model_authorization_providers(classes = ModelAuthorizationProvider.descendants) click to toggle source

Return a list of authorization providers for authorizer to detect which one to use. @see Wallaby::ModelAuthorizationProvider @return [ActiveSupport::HashWithIndifferentAccess<String, Class>] authorization provider hash @since wallaby-5.2.0

# File lib/interfaces/wallaby/mode.rb, line 43
def model_authorization_providers(classes = ModelAuthorizationProvider.descendants)
  # NOTE: make sure default provider always comes last
  @model_authorization_providers ||=
    classes
    .select { |klass| klass.name.include? name }
    .sort_by { |klass| klass.provider_name == DEFAULT_PROVIDER ? 1 : 0 }
    .each_with_object(::ActiveSupport::HashWithIndifferentAccess.new) do |klass, hash|
      hash[klass.provider_name] = klass
    end
end
model_decorator() click to toggle source

@see Wallaby::ModelDecorator @return [Class] model decorator for the mode

# File lib/interfaces/wallaby/mode.rb, line 9
def model_decorator
  check_and_constantize __callee__
end
model_finder() click to toggle source

@see Wallaby::ModelFinder @return [Class] model finder for the mode

# File lib/interfaces/wallaby/mode.rb, line 15
def model_finder
  check_and_constantize __callee__
end
model_pagination_provider() click to toggle source

@see Wallaby::ModelPaginationProvider @return [Class] pagination provider for the mode @since wallaby-5.2.0

# File lib/interfaces/wallaby/mode.rb, line 28
def model_pagination_provider
  check_and_constantize __callee__
end
model_service_provider() click to toggle source

@see Wallaby::ModelServiceProvider @return [Class] service provider for the mode

# File lib/interfaces/wallaby/mode.rb, line 21
def model_service_provider
  check_and_constantize __callee__
end

Private Class Methods

check_and_constantize(method_id) click to toggle source

@return [Class] constantized class

# File lib/interfaces/wallaby/mode.rb, line 57
def check_and_constantize(method_id)
  method_class = method_id.to_s.classify
  class_name = "#{name}::#{method_class}"
  parent_class = "Wallaby::#{method_class}".constantize
  class_name.constantize.tap do |klass|
    next if klass < parent_class

    raise InvalidError, Locale.t('mode.inherit_required', klass: klass, parent: parent_class)
  end
rescue NameError => e
  Logger.error e
  raise NotImplemented, class_name
end