Skip to content

Commit ede9870

Browse files
authored
Optimize file path to class name conversion (#3589)
1 parent e83fb0b commit ede9870

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

lib/rails_admin/config.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,19 +364,16 @@ def visible_models(bindings)
364364

365365
private
366366

367-
def lchomp(base, arg)
368-
base.to_s.reverse.chomp(arg.to_s.reverse).reverse
369-
end
370-
371367
def viable_models
372368
included_models.collect(&:to_s).presence || begin
373369
@@system_models ||= # memoization for tests
374370
([Rails.application] + Rails::Engine.subclasses.collect(&:instance)).flat_map do |app|
375371
(app.paths['app/models'].to_a + app.config.eager_load_paths).collect do |load_path|
376372
Dir.glob(app.root.join(load_path)).collect do |load_dir|
373+
path_prefix = "#{app.root.join(load_dir)}/"
377374
Dir.glob("#{load_dir}/**/*.rb").collect do |filename|
378375
# app/models/module/class.rb => module/class.rb => module/class => Module::Class
379-
lchomp(filename, "#{app.root.join(load_dir)}/").chomp('.rb').camelize
376+
filename.delete_prefix(path_prefix).chomp('.rb').camelize
380377
end
381378
end
382379
end

0 commit comments

Comments
 (0)