<commit_before>plugins_root = Rails.env.test? ? 'plugins' : File.join('config', 'plugins')

Dir.glob(File.join(Rails.root, plugins_root, '*', 'controllers')) do |controllers_dir|
  prefixes_by_folder = {'public' => 'plugin',
                        'profile' => 'profile/:profile/plugin',
                        'myprofile' => 'myprofile/:profile/plugin',
                        'admin' => 'admin/plugin'}

  controllers_by_folder = prefixes_by_folder.keys.inject({}) do |hash, folder|
    hash.merge!({folder => Dir.glob(File.join(controllers_dir, folder, '*')).map {|full_names| File.basename(full_names).gsub(/_controller.rb$/,'')}})
  end

  plugin_name = File.basename(File.dirname(controllers_dir))

  controllers_by_folder.each do |folder, controllers|
    controllers.each do |controller|
      controller_name = controller.gsub("#{plugin_name}_plugin_",'')
      map.connect "#{prefixes_by_folder[folder]}/#{plugin_name}/#{controller_name}/:action/:id", :controller => controller
    end
  end

  map.connect 'plugin/' + plugin_name + '/:action/:id', :controller => plugin_name + '_plugin'
  map.connect 'profile/:profile/plugin/' + plugin_name + '/:action/:id', :controller => plugin_name + '_plugin_profile'
  map.connect 'myprofile/:profile/plugin/' + plugin_name + '/:action/:id', :controller => plugin_name + '_plugin_myprofile'
  map.connect 'admin/plugin/' + plugin_name + '/:action/:id', :controller => plugin_name + '_plugin_admin'
end<commit_msg>Use profile format in plugins' routes<commit_after>plugins_root = Rails.env.test? ? 'plugins' : File.join('config', 'plugins')

Dir.glob(File.join(Rails.root, plugins_root, '*', 'controllers')) do |controllers_dir|
  prefixes_by_folder = {'public' => 'plugin',
                        'profile' => 'profile/:profile/plugin',
                        'myprofile' => 'myprofile/:profile/plugin',
                        'admin' => 'admin/plugin'}

  controllers_by_folder = prefixes_by_folder.keys.inject({}) do |hash, folder|
    hash.merge!({folder => Dir.glob(File.join(controllers_dir, folder, '*')).map {|full_names| File.basename(full_names).gsub(/_controller.rb$/,'')}})
  end

  plugin_name = File.basename(File.dirname(controllers_dir))

  controllers_by_folder.each do |folder, controllers|
    controllers.each do |controller|
      controller_name = controller.gsub("#{plugin_name}_plugin_",'')
      map.connect "#{prefixes_by_folder[folder]}/#{plugin_name}/#{controller_name}/:action/:id", :controller => controller, :profile => /#{Noosfero.identifier_format}/
    end
  end

  map.connect 'plugin/' + plugin_name + '/:action/:id', :controller => plugin_name + '_plugin'
  map.connect 'profile/:profile/plugin/' + plugin_name + '/:action/:id', :controller => plugin_name + '_plugin_profile', :profile => /#{Noosfero.identifier_format}/
  map.connect 'myprofile/:profile/plugin/' + plugin_name + '/:action/:id', :controller => plugin_name + '_plugin_myprofile', :profile => /#{Noosfero.identifier_format}/
  map.connect 'admin/plugin/' + plugin_name + '/:action/:id', :controller => plugin_name + '_plugin_admin'
end
{'fraction_non_alphanumeric': 0.17361784675072744, 'fraction_numerical': 0.0, 'mean_word_length': 4.2979452054794525, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, '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': '3840903', 'n_tokens_mistral': 968, 'n_tokens_neox': 970, 'n_words': 164}