lib/madmin.rb in madmin-0.1.0 vs lib/madmin.rb in madmin-0.1.1

- old
+ new

@@ -1,30 +1,40 @@ require "madmin/engine" -require "madmin/resourceable" -require "madmin/resources" +require "pagy" + module Madmin - class NoResourcesError < StandardError; end - class ResourceNotFoundError < StandardError; end - class WrongArgumentError < StandardError; end - class UndefinedScopeError < StandardError; end - class ScopeWithArgumentsError < StandardError; end + autoload :Field, "madmin/field" + autoload :GeneratorHelpers, "madmin/generator_helpers" + autoload :Resource, "madmin/resource" - autoload :Field, "madmin/field" - autoload :Resourceable, "madmin/resourceable" + module Fields + autoload :Boolean, "madmin/fields/boolean" + autoload :Integer, "madmin/fields/integer" + autoload :String, "madmin/fields/string" + autoload :Text, "madmin/fields/text" + autoload :Date, "madmin/fields/date" + autoload :DateTime, "madmin/fields/date_time" + autoload :Json, "madmin/fields/json" + autoload :Enum, "madmin/fields/enum" + autoload :Float, "madmin/fields/float" + autoload :Time, "madmin/fields/time" + autoload :BelongsTo, "madmin/fields/belongs_to" + autoload :Polymorphic, "madmin/fields/polymorphic" + autoload :HasMany, "madmin/fields/has_many" + autoload :HasOne, "madmin/fields/has_one" + autoload :RichText, "madmin/fields/rich_text" + autoload :Attachment, "madmin/fields/attachment" + autoload :Attachments, "madmin/fields/attachments" + end - class Field - autoload :Associatable, "madmin/field/associatable" - autoload :BelongsTo, "madmin/field/belongs_to" - autoload :CheckBox, "madmin/field/check_box" - autoload :DateTime, "madmin/field/date_time" - autoload :Email, "madmin/field/email" - autoload :HasMany, "madmin/field/has_many" - autoload :HasOne, "madmin/field/has_one" - autoload :Number, "madmin/field/number" - autoload :Password, "madmin/field/password" - autoload :Polymorphic, "madmin/field/polymorphic" - autoload :Select, "madmin/field/select" - autoload :TextArea, "madmin/field/text_area" - autoload :Text, "madmin/field/text" + mattr_accessor :resources, default: [] + + class << self + def resource_for(object) + Rails.application.eager_load! + + klass_name = object.class.name + Madmin.resources.find { |r| r.model_name == klass_name } + end end end