Sha256: a25f55cafe390f8b42ca22b174bed7cbe8295cb6c67f0a312d69b2a11561c115

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents

require 'zeitwerk'
require 'slim'
require 'cm_admin/version'
require 'cm_admin/engine'
require 'cm_admin/model'
require 'cm_admin/view_helpers'
require 'cm_admin/utils'
require 'cm_admin/configuration'

ActiveSupport.on_load(:active_record) do
  module ActiveRecord
    class Base
      def self.cm_admin(&block)
        CmAdmin.initialize_model(self, &block)
      end
    end
  end
end

module CmAdmin
  # autoload :Model, 'cm_admin/model'
  # autoload :ViewHelpers, 'cm_admin/view_helpers'

  class Error < StandardError; end

  mattr_accessor :layout, :authorized_roles
  mattr_accessor :included_models, :cm_admin_models
  @@authorized_roles ||= []
  @@included_models ||= []
  @@cm_admin_models ||= []

  class << self
    def configure
      # instance_eval(&block)
      @config ||= Configuration.new
      yield(@config)
    end

    def layout; end

    def config
      @config ||= Configuration.new
    end

    def initialize_model(entity, &block)
      return unless entity.is_a?(Class)
      CmAdmin::Model.delete_entity(entity.name) if CmAdmin::Model.find_by({ name: entity.name })

      config.cm_admin_models << CmAdmin::Model.new(entity, &block)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cm-admin-4.4.8 lib/cm_admin.rb
cm-admin-4.4.6 lib/cm_admin.rb
cm-admin-4.4.1 lib/cm_admin.rb
cm-admin-4.4.0 lib/cm_admin.rb
cm-admin-4.3.0 lib/cm_admin.rb