Sha256: cf8a36cc7293eec61cf2fe0f0a449460365dfc6c2ad434a9bdc3e32d24420b7d

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

module AbAdmin
  module Generators
    class ModelGenerator < Rails::Generators::NamedBase
      include Rails::Generators::ResourceHelpers

      desc 'Generates AbAdmin dsl resource for model'

      source_root File.expand_path('../templates', __FILE__)
      check_class_collision :prefix => 'AbAdmin'

      def create_resource_file
        template 'resource.erb', File.join('app/models/ab_admin', "ab_admin_#{singular_name}.rb")
      end

      def add_menu
        menu_code = "model #{model.name}"
        log :menu, menu_code
        sentinel = /draw do$/

        in_root do
          inject_into_file 'app/models/admin_menu.rb', "\n    #{menu_code}\n", {:after => sentinel, :verbose => false}
        end
      end

      def model
        @model ||= class_name.constantize
      end

      protected

      def model_instance
        @model_instance ||= model.new
      end

      def translated_columns
        @translated_columns ||= model.respond_to?(:translated_attribute_names) ? model.translated_attribute_names.map(&:to_s) : []
      end

      def index_attrs
        @attrs ||= model_instance.attributes.keys.map(&:to_s)
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ab_admin-0.2.3 lib/generators/ab_admin/model/model_generator.rb
ab_admin-0.2.2 lib/generators/ab_admin/model/model_generator.rb
ab_admin-0.2.1 lib/generators/ab_admin/model/model_generator.rb
ab_admin-0.2.0 lib/generators/ab_admin/model/model_generator.rb
ab_admin-0.1.2 lib/generators/ab_admin/model/model_generator.rb
ab_admin-0.1.1 lib/generators/ab_admin/model/model_generator.rb
ab_admin-0.1.0 lib/generators/ab_admin/model/model_generator.rb