Class: Gbc::Trestle::ResourceGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Gbc::Trestle::ResourceGenerator
- Defined in:
- lib/generators/gbc/trestle/resource_generator.rb
Instance Method Summary collapse
- #create_admin_folder ⇒ Object
- #create_collection_template ⇒ Object
- #create_controller_template ⇒ Object
- #create_form_template ⇒ Object
- #create_routes_template ⇒ Object
- #create_scopes_template ⇒ Object
- #create_search_template ⇒ Object
- #create_table_template ⇒ Object
- #info1 ⇒ Object
- #info2 ⇒ Object
-
#process_admin_template ⇒ Object
Process and copy the main admin template file.
- #start ⇒ Object
Instance Method Details
#create_admin_folder ⇒ Object
26 27 28 29 30 |
# File 'lib/generators/gbc/trestle/resource_generator.rb', line 26 def create_admin_folder # `empty_directory` ensures the directory exists and is empty if it was there before. empty_directory admin_folder_path # `say_status` provides feedback to the user in the console. end |
#create_collection_template ⇒ Object
59 60 61 62 63 |
# File 'lib/generators/gbc/trestle/resource_generator.rb', line 59 def create_collection_template # `copy_file` copies a file from the source_root to the destination path. # No ERB processing is done here. template "template_collection.rb.erb", "#{admin_folder_path}/collection.rb" end |
#create_controller_template ⇒ Object
77 78 79 80 81 |
# File 'lib/generators/gbc/trestle/resource_generator.rb', line 77 def create_controller_template # `copy_file` copies a file from the source_root to the destination path. # No ERB processing is done here. template "template_controller.rb.erb", "#{admin_folder_path}/controller.rb" end |
#create_form_template ⇒ Object
47 48 49 50 51 |
# File 'lib/generators/gbc/trestle/resource_generator.rb', line 47 def create_form_template # `copy_file` copies a file from the source_root to the destination path. # No ERB processing is done here. template "template_form.rb.erb", "#{admin_folder_path}/form.rb" end |
#create_routes_template ⇒ Object
53 54 55 56 57 |
# File 'lib/generators/gbc/trestle/resource_generator.rb', line 53 def create_routes_template # `copy_file` copies a file from the source_root to the destination path. # No ERB processing is done here. template "template_routes.rb.erb", "#{admin_folder_path}/routes.rb" end |
#create_scopes_template ⇒ Object
65 66 67 68 69 |
# File 'lib/generators/gbc/trestle/resource_generator.rb', line 65 def create_scopes_template # `copy_file` copies a file from the source_root to the destination path. # No ERB processing is done here. template "template_scopes.rb.erb", "#{admin_folder_path}/scopes.rb" end |
#create_search_template ⇒ Object
71 72 73 74 75 |
# File 'lib/generators/gbc/trestle/resource_generator.rb', line 71 def create_search_template # `copy_file` copies a file from the source_root to the destination path. # No ERB processing is done here. template "template_search.rb.erb", "#{admin_folder_path}/search.rb" end |
#create_table_template ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/generators/gbc/trestle/resource_generator.rb', line 32 def create_table_template # `copy_file` copies a file from the source_root to the destination path. # No ERB processing is done here. if model.present? puts "Info: Attempting to fetch attributes for model: #{model}" model_class = Gbc::ModelInspector.find_active_record_model(model) puts "Info: Found model class: #{model_class}" if model_class puts "Info: Attempting to fetch attributes for model: #{model}" @model_database_attributes = Gbc::ModelInspector.get_model_database_attributes(model_class) end end template "template_table.rb.erb", "#{admin_folder_path}/table.rb" end |
#info1 ⇒ Object
22 23 24 |
# File 'lib/generators/gbc/trestle/resource_generator.rb', line 22 def info1 say_status "building", "Building supporting files" end |
#info2 ⇒ Object
83 84 85 |
# File 'lib/generators/gbc/trestle/resource_generator.rb', line 83 def info2 say_status "Finishing", "Creating the admin file to tie things up" end |
#process_admin_template ⇒ Object
Process and copy the main admin template file.
88 89 90 91 92 93 |
# File 'lib/generators/gbc/trestle/resource_generator.rb', line 88 def process_admin_template # `template` processes an ERB file and copies the result. # Variables defined in this generator class (like `file_name`, `model_name_snake_cased`) # are accessible within the ERB template. template "template_admin.rb.erb", "#{admin_root_path}/#{file_name}_admin.rb" end |
#start ⇒ Object
18 19 20 |
# File 'lib/generators/gbc/trestle/resource_generator.rb', line 18 def start say_status "building", "Building new Trestle resource" end |