<commit_before>class Rango
  class RouterStrategy
    def register
      # TODO: different strategies for each router
      Rango::Router.strategies.push(self)
    end
  end

  # to("Post#show", "blog/views")
  # => Post.new(request).show(*args)
  class ControllerStrategy < RouterStrategy
    def match?(route)
      route.file && route.callable.is_a?(String)
    end

    def run(route, request, params)
      Project.import(route.file) if route.file
      args = params.map { |key, value| value }
      klass, method = route.callable.split("#")
      controller = klass.new
      controller.request = request
      controller.params  = params
      controller.method(method).call(*args)
    end
  end

  # to(Rango.logger.method(:debug))
  # => Rango.logger.debug(request, *args)
  class CallableStrategy < RouterStrategy
    def match?(route)
      (not route.file) && route.callable.respond_to?(:call)
    end

    def run(route, request, params)
      args = params.map { |key, value| value }
      route.callable.call(request, *args)
    end
  end
end<commit_msg>Improved strategies, it logs when strategy is registered, improved matching of correct strategy and fixed method run in ControllerStrategy.<commit_after>class Rango
  class RouterStrategy
    def register
      # TODO: different strategies for each router
      Rango::Router.strategies.push(self)
      Rango.logger.debug("Strategy #{self} have been registered")
    end
  end

  # to("Post#show", "blog/views")
  # => Post.new(request).show(*args)
  class ControllerStrategy < RouterStrategy
    def match?(request, params, *args, &block)
      args.length.eql?(2) && args.all? { |arg| arg.is_a?(String) } && !block_given?
    end

    def run(request, params, *args, &block)
      file = args.first
      callable = args.last
      Project.import(file) if file.is_a?(String)
      args = params.map { |key, value| value }
      klass_name, method = callable.split("#")
      klass = Object.const_get(klass_name)
      controller = klass.new
      controller.request = request
      controller.params  = params
      controller.method(method).call(*args)
    end
  end

  # to(Rango.logger.method(:debug))
  # => Rango.logger.debug(request, *args)
  class CallableStrategy < RouterStrategy
    def match?(request, params, *args, &block)
      (args.length.eql?(1) && args.first.respond_to?(:call)) || block_given?
    end

    def run(request, params, *args, &block)
      callable = args.first || block
      args = params.map { |key, value| value }
      callable.call(request, *args)
    end
  end
end
{'fraction_non_alphanumeric': 0.12422360248447205, 'fraction_numerical': 0.0007763975155279503, 'mean_word_length': 3.1232, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6515134', 'n_tokens_mistral': 799, 'n_tokens_neox': 802, 'n_words': 194}