Class: ScaffoldAdminGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- ScaffoldAdminGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/scaffold_admin/scaffold_admin_generator.rb
Class Method Summary collapse
-
.next_migration_number(dirname) ⇒ Object
FIXME: Should be proxied to ActiveRecord::Generators::Base Implement the required interface for Rails::Generators::Migration.
Instance Method Summary collapse
- #args_attributes ⇒ Object
- #array_views ⇒ Object
- #class_name ⇒ Object
- #create_migration ⇒ Object
- #create_templates ⇒ Object
-
#model_attributes_names ⇒ Object
class_option :index, type: :boolean, default: true, desc: “Include index” puts index exit.
- #model_name ⇒ Object
- #module_name ⇒ Object
- #namespace_name ⇒ Object
- #namespace_underscore ⇒ Object
- #plural_class ⇒ Object
- #plural_name ⇒ Object
- #singular_name ⇒ Object
- #split_scaffold_name ⇒ Object
Class Method Details
.next_migration_number(dirname) ⇒ Object
FIXME: Should be proxied to ActiveRecord::Generators::Base Implement the required interface for Rails::Generators::Migration.
122 123 124 125 126 127 128 |
# File 'lib/generators/scaffold_admin/scaffold_admin_generator.rb', line 122 def self.next_migration_number(dirname) #:nodoc: if ActiveRecord::Base. Time.now.utc.strftime("%Y%m%d%H%M%S") else "%.3d" % (current_migration_number(dirname) + 1) end end |
Instance Method Details
#args_attributes ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/generators/scaffold_admin/scaffold_admin_generator.rb', line 71 def args_attributes @model_attributes = [] attributes.each do |arg| if arg.include?(':') @model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':')) end end @model_attributes.uniq! end |
#array_views ⇒ Object
59 60 61 |
# File 'lib/generators/scaffold_admin/scaffold_admin_generator.rb', line 59 def array_views %w[edit _form index new show] end |
#class_name ⇒ Object
96 97 98 |
# File 'lib/generators/scaffold_admin/scaffold_admin_generator.rb', line 96 def class_name model_name.titlecase.gsub(/[\-\/" "]/, "") end |
#create_migration ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/generators/scaffold_admin/scaffold_admin_generator.rb', line 51 def create_migration if namespace_name migration_template "migration.rb", "db/migrate/create_#{namespace_underscore}_#{plural_name}.rb" else migration_template "migration.rb", "db/migrate/create_#{plural_name}.rb" end end |
#create_templates ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/scaffold_admin/scaffold_admin_generator.rb', line 25 def create_templates args_attributes if namespace_name template "model.rb", "app/models/#{namespace_underscore}/#{singular_name}.rb" template "controller.rb", "app/controllers/#{namespace_underscore}/#{plural_name}_controller.rb" template "helper.rb", "app/helpers/#{namespace_underscore}/#{plural_name}_helper.rb" array_views.each do |view| template "views/#{view}.html.erb", "app/views/#{namespace_underscore}/#{plural_name}/#{view}.html.erb" end else template "model.rb", "app/models/#{singular_name}.rb" template "controller.rb", "app/controllers/#{plural_name}_controller.rb" template "helper.rb", "app/helpers/#{plural_name}_helper.rb" array_views.each do |view| template "views/#{view}.html.erb", "app/views/#{plural_name}/#{view}.html.erb" end end route "resources :#{plural_name}" end |
#model_attributes_names ⇒ Object
class_option :index, type: :boolean, default: true, desc: “Include index” puts index exit
15 16 17 18 19 20 21 22 23 |
# File 'lib/generators/scaffold_admin/scaffold_admin_generator.rb', line 15 def model_attributes_names @model_attributes_names = [] attributes.each do |attribute| @model_attributes_names << attribute.gsub(/:(.*)/, "") end @model_attributes_names.join(', :') end |
#model_name ⇒ Object
84 85 86 |
# File 'lib/generators/scaffold_admin/scaffold_admin_generator.rb', line 84 def model_name split_scaffold_name[:model_name] end |
#module_name ⇒ Object
108 109 110 111 112 |
# File 'lib/generators/scaffold_admin/scaffold_admin_generator.rb', line 108 def module_name unless namespace_name.nil? namespace_name.titlecase.gsub(/[\-\/" "]/, "") end end |
#namespace_name ⇒ Object
88 89 90 |
# File 'lib/generators/scaffold_admin/scaffold_admin_generator.rb', line 88 def namespace_name split_scaffold_name[:namespace] end |
#namespace_underscore ⇒ Object
114 115 116 117 118 |
# File 'lib/generators/scaffold_admin/scaffold_admin_generator.rb', line 114 def namespace_underscore unless namespace_name.nil? namespace_name.underscore end end |
#plural_class ⇒ Object
104 105 106 |
# File 'lib/generators/scaffold_admin/scaffold_admin_generator.rb', line 104 def plural_class class_name.pluralize end |
#plural_name ⇒ Object
100 101 102 |
# File 'lib/generators/scaffold_admin/scaffold_admin_generator.rb', line 100 def plural_name model_name.underscore.pluralize end |
#singular_name ⇒ Object
92 93 94 |
# File 'lib/generators/scaffold_admin/scaffold_admin_generator.rb', line 92 def singular_name model_name.underscore end |
#split_scaffold_name ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/generators/scaffold_admin/scaffold_admin_generator.rb', line 63 def split_scaffold_name path = {} namespace = scaffold_name.split('/') path[:model_name] = namespace.pop path[:namespace] = namespace.pop path end |