Sha256: fd6f8e63d02cff39aa30e076f0d9f7b77f89290fa75b9c60fe4484d54575bfe6

Contents?: true

Size: 874 Bytes

Versions: 3

Compression:

Stored size: 874 Bytes

Contents

module SimpleAdmin
  module ResourceController
    class ControllerBuilder
      # Build controller class by resource name
      # @example ArticlesController
      #  controller_builder = SimpleAdmin::ResourceController::ControllerBuilder.new(:articles)
      #  controller_builder.build!
      #
      #  => controller_builder.controller_klass
      #  => SimpleAdmin::Admin::ArticlesController
      #
      # @since 0.1.0

      attr_reader :controller_name

      def initialize(resource_name)
        @controller_name = "#{resource_name.camelize}Controller"
      end

      def build!
        unless SimpleAdmin::Admin.const_defined?(controller_name)
          Admin.const_set(controller_name, Class.new(SimpleAdmin::Admin::ApplicationController))
        end
      end

      def controller_klass
        Admin.const_get(controller_name)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
simple-admin-0.1.2.pre.alpha lib/simple_admin/resource_controller/controller_builder.rb
simple-admin-0.1.1.pre.alpha lib/simple_admin/resource_controller/controller_builder.rb
simple-admin-0.1.0.pre.alpha lib/simple_admin/resource_controller/controller_builder.rb