lib/madmin.rb in madmin-1.2.0 vs lib/madmin.rb in madmin-1.2.1

- old
+ new

@@ -4,10 +4,11 @@ module Madmin autoload :Field, "madmin/field" autoload :GeneratorHelpers, "madmin/generator_helpers" autoload :Resource, "madmin/resource" + autoload :Search, "madmin/search" module Fields autoload :Attachment, "madmin/fields/attachment" autoload :Attachments, "madmin/fields/attachments" autoload :BelongsTo, "madmin/fields/belongs_to" @@ -28,16 +29,29 @@ autoload :String, "madmin/fields/string" autoload :Text, "madmin/fields/text" autoload :Time, "madmin/fields/time" end - mattr_accessor :resources, default: [] - class << self def resource_for(object) - Rails.application.eager_load! + "#{object.class.name}Resource".constantize + end - klass_name = object.class.name - Madmin.resources.find { |r| r.model_name == klass_name } + def resource_by_name(name) + "#{name}Resource".constantize + end + + def resources + @resources ||= resource_names.map(&:constantize) + end + + def reset_resources! + @resources = nil + end + + def resource_names + root = Rails.root.join("app/madmin/resources/") + files = Dir.glob(root.join("**/*.rb")) + files.sort!.map! { |f| f.split(root.to_s).last.delete_suffix(".rb").classify } end end end