<commit_before>if Rails.env.development?
  # NOTE: Rails reload! will hit here
  Rails.logger.debug '--> [ Wallaby ] Ready to preload and clear cache on reload. <--'
  Rails.cache.delete_matched %r(\Awallaby/)

  # NOTE: we search for subclasses of Wallaby::ResourcesController and Wallaby::ResourceDecorator.
  # therefore, under development environment, we need to preload all classes under /app folder in main_app
  # using `require` is not working for preloading, we need to classify the class names to make Rails reload classes properly
  Wallaby::ApplicationController

  Dir[ 'app/**/*.rb' ].each do |file_path|
    name = file_path[ %r(app/[^/]+/(.+)\.rb), 1 ]
    name.classify.constantize
  end
end

class Wallaby::ResourcesRouter
  DEFAULT_CONTROLLER = Wallaby::ResourcesController

  def call(env)
    params = env['action_dispatch.request.path_parameters']
    find_controller_by(params[:resources]).action(params[:action]).call env
  rescue AbstractController::ActionNotFound, Wallaby::ModelNotFound
    DEFAULT_CONTROLLER.action(:not_found).call env
  end

  protected
  def cached_subclasses
    Rails.cache.fetch 'wallaby/resources_router' do
      DEFAULT_CONTROLLER.subclasses.reject do |klass|
        klass.name.blank?
      end
    end
  end

  def find_controller_by(resources_name)
    model_class = Wallaby::Utils.to_model_class resources_name
    cached_subclasses.find do |klass|
      klass.model_class == model_class
    end or DEFAULT_CONTROLLER
  end
end
<commit_msg>need to rescue the constantize since some files might not follow the naming convention<commit_after>if Rails.env.development?
  # NOTE: Rails reload! will hit here
  Rails.logger.debug '--> [ Wallaby ] Ready to preload and clear cache on reload. <--'
  Rails.cache.delete_matched %r(\Awallaby/)

  # NOTE: we search for subclasses of Wallaby::ResourcesController and Wallaby::ResourceDecorator.
  # therefore, under development environment, we need to preload all classes under /app folder in main_app
  # using `require` is not working for preloading, we need to constantize the class names to make Rails reload classes properly
  Wallaby::ApplicationController

  Dir[ 'app/**/*.rb' ].each do |file_path|
    name = file_path[ %r(app/[^/]+/(.+)\.rb), 1 ]
    name.classify.constantize rescue nil
  end
end

class Wallaby::ResourcesRouter
  DEFAULT_CONTROLLER = Wallaby::ResourcesController

  def call(env)
    params = env['action_dispatch.request.path_parameters']
    find_controller_by(params[:resources]).action(params[:action]).call env
  rescue AbstractController::ActionNotFound, Wallaby::ModelNotFound
    DEFAULT_CONTROLLER.action(:not_found).call env
  end

  protected
  def cached_subclasses
    Rails.cache.fetch 'wallaby/resources_router' do
      DEFAULT_CONTROLLER.subclasses.reject do |klass|
        klass.name.blank?
      end
    end
  end

  def find_controller_by(resources_name)
    model_class = Wallaby::Utils.to_model_class resources_name
    cached_subclasses.find do |klass|
      klass.model_class == model_class
    end or DEFAULT_CONTROLLER
  end
end

{'fraction_non_alphanumeric': 0.09146934803762569, 'fraction_numerical': 0.0006487187804086928, 'mean_word_length': 4.244897959183674, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6423665', 'n_tokens_mistral': 936, 'n_tokens_neox': 911, 'n_words': 257}