module TalentScout::Controller::ClassMethods

Public Instance Methods

model_search_class() click to toggle source

Returns the controller model search class. Defaults to a class corresponding to the singular form of the controller name. The model search class can also be set with {model_search_class=}. If the model search class has not been set, and the default class does not exist, a NameError will be raised.

@example

class PostsController < ApplicationController
end

PostsController.model_search_class  # == PostSearch (class)

@return [Class<TalentScout::ModelSearch>] @raise [NameError]

if the model search class has not been set and the default
class does not exist
# File lib/talent_scout/controller.rb, line 22
def model_search_class
  @model_search_class ||= "#{controller_path.classify}Search".constantize
end
model_search_class=(klass) click to toggle source

Sets the controller model search class. See {model_search_class}.

@param klass [Class<TalentScout::ModelSearch>] @return [Class<TalentScout::ModelSearch>]

# File lib/talent_scout/controller.rb, line 30
def model_search_class=(klass)
  @model_search_class = klass
end
model_search_class?() click to toggle source

Similar to {model_search_class}, but returns nil instead of raising an error when the value has not been set and the default class does not exist.

@return [Class<TalentScout::ModelSearch>, nil]

# File lib/talent_scout/controller.rb, line 39
def model_search_class?
  return @model_search_class if defined?(@model_search_class)
  begin
    model_search_class
  rescue NameError
    @model_search_class = nil
  end
end