Class: Gbc::Trestle::ResourceGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/gbc/trestle/resource_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_admin_folderObject



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_templateObject



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_templateObject



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_templateObject



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_templateObject



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_templateObject



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_templateObject



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_templateObject



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

#info1Object



22
23
24
# File 'lib/generators/gbc/trestle/resource_generator.rb', line 22

def info1
  say_status "building", "Building supporting files"
end

#info2Object



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_templateObject

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

#startObject



18
19
20
# File 'lib/generators/gbc/trestle/resource_generator.rb', line 18

def start
  say_status "building", "Building new Trestle resource"
end