Class: AbAdmin::Generators::ModelGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Rails::Generators::ResourceHelpers
Defined in:
lib/generators/ab_admin/model/model_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_menuObject


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/generators/ab_admin/model/model_generator.rb', line 15

def add_menu
  menu_path = 'app/models/admin_menu.rb'
  return if File.read(File.join(@destination_stack.last, menu_path)).match(Regexp.new("[^a-zA-Z]#{model.name}[^a-zA-Z]"))
  menu_code = "model #{model.name}"
  log :menu, menu_code
  sentinel = /draw do$/

  in_root do
    inject_into_file menu_path, "\n    #{menu_code}\n", {after: sentinel, verbose: false}
  end
end

#create_resource_fileObject


11
12
13
# File 'lib/generators/ab_admin/model/model_generator.rb', line 11

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

#modelObject


27
28
29
# File 'lib/generators/ab_admin/model/model_generator.rb', line 27

def model
  @model ||= class_name.constantize
end