Class: PropelApi::ControllerGenerator

Inherits:
NamedBase
  • Object
show all
Defined in:
lib/generators/propel_api/controller/controller_generator.rb

Instance Method Summary collapse

Methods included from ConfigurationMethods

included

Instance Method Details

#add_routesObject



88
89
90
# File 'lib/generators/propel_api/controller/controller_generator.rb', line 88

def add_routes
  create_propel_routes
end

#check_dependencies_before_destroyObject



79
80
81
82
# File 'lib/generators/propel_api/controller/controller_generator.rb', line 79

def check_dependencies_before_destroy
  # Only check critical dependencies during destroy operations
  check_for_critical_dependencies if behavior == :revoke
end

#create_controllerObject



84
85
86
# File 'lib/generators/propel_api/controller/controller_generator.rb', line 84

def create_controller
  create_propel_controller_template
end

#create_controller_testObject



92
93
94
# File 'lib/generators/propel_api/controller/controller_generator.rb', line 92

def create_controller_test
  create_propel_controller_test
end

#create_integration_testObject



96
97
98
# File 'lib/generators/propel_api/controller/controller_generator.rb', line 96

def create_integration_test
  create_propel_integration_test
end

#show_completion_messageObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/generators/propel_api/controller/controller_generator.rb', line 100

def show_completion_message
  # Use shared completion message framework from Base class
  generated_files = [
    "๐ŸŽฎ Controller: app/controllers/#{controller_path}/#{controller_file_name}.rb",
    "๐Ÿงช Controller Tests: test/controllers/#{controller_path}/#{controller_file_name}_test.rb",
    "๐Ÿงช Integration Tests: test/integration/#{file_name}_api_test.rb"
  ]
  
  next_steps = [
    "Test your API: GET #{api_route_path}",
    "Run tests: rails test test/controllers/#{controller_path}/#{controller_file_name}_test.rb",
    "Run integration tests: rails test test/integration/#{file_name}_api_test.rb"
  ]
  
  if @adapter == 'propel_facets'
    next_steps << "Customize facets in: app/models/#{file_name}.rb"
  end
  
  show_propel_completion_message(
    resource_type: "Controller",
    generated_files: generated_files,
    next_steps: next_steps
  )
end

#validate_model_existsObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/generators/propel_api/controller/controller_generator.rb', line 57

def validate_model_exists
  # Ensure attributes are parsed before validation
  parse_attributes_from_args
  
  # Only require model when auto-introspection is needed
  model_file_exists = File.exist?(File.join(destination_root, "app/models/#{file_name}.rb"))
  
  if should_auto_introspect? && !model_file_exists
    raise Thor::Error, "Model #{class_name} does not exist. Please create the model first or use 'rails generate propel_api #{class_name}' to create the complete resource."
  end
  
  # Show educational warning when no explicit choice is made
  if !options[:all_attributes] && (@attributes.nil? || @attributes.empty?) && model_file_exists
    show_auto_introspection_warning
  end      
  # Process polymorphic parent information if provided
  process_polymorphic_parents if options[:parents].present?
  
  # Validate attributes if not using introspection
  validate_attributes_exist unless should_auto_introspect?
end