Class: PropelApi::InstallGenerator

Inherits:
Base
  • Object
show all
Defined in:
lib/generators/propel_api/install/install_generator.rb

Instance Method Summary collapse

Methods included from ConfigurationMethods

included

Instance Method Details

#add_required_gemsObject



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/generators/propel_api/install/install_generator.rb', line 78

def add_required_gems
  if behavior == :revoke
    say "💎 Note: Gems added during installation are still in your Gemfile", :yellow
    say "   Remove manually if no longer needed: faker, pagy, has_scope, ransack#{', graphiti, graphiti-rails, vandal_ui' if @adapter == 'graphiti'}", :yellow
  else
    case @adapter
    when 'graphiti'
      add_graphiti_gems
    when 'propel_facets'
      add_propel_facets_gems
    end
  end
end

#copy_api_controllerObject



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
50
51
52
53
54
# File 'lib/generators/propel_api/install/install_generator.rb', line 25

def copy_api_controller
  initialize_propel_api_settings
  
  if behavior == :revoke
    say "Removing API controller with #{@adapter} adapter", :red
    say "Using namespace: #{namespace_display} version: #{version_display}", :blue
  else
    say "Installing API controller with #{@adapter} adapter", :green
    say "Using namespace: #{namespace_display} version: #{version_display}", :blue
    
    # Create Api::BaseController first
    create_api_base_controller
    
    # Optionally enhance CSRF error messages (non-breaking)
    add_csrf_error_handling
    
    # Add dynamic filtering capabilities to ApplicationRecord
    add_model_filters_concern
  end
  
  case @adapter
  when 'graphiti'
    copy_graphiti_controller
    generate_graphiti_resources if respond_to?(:generate_graphiti_resources, true)
  when 'propel_facets'
    copy_propel_facets_controller
  else
    raise "Unknown adapter: #{@adapter}. Supported: 'propel_facets', 'graphiti'"
  end
end

#create_api_routesObject



68
69
70
71
72
73
74
75
76
# File 'lib/generators/propel_api/install/install_generator.rb', line 68

def create_api_routes
  if behavior == :revoke
    # Remove API namespace structure
    remove_api_namespace
  else
    # Add basic API namespace structure (defaults to api/v1)
    add_api_namespace
  end
end

#create_configurationObject



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/generators/propel_api/install/install_generator.rb', line 56

def create_configuration
  if behavior == :revoke
    remove_file "config/initializers/propel_api.rb"
    # Rails automatically handles file removal, just show appropriate message
    say "Removed PropelApi configuration", :red
  else
    # Create the PropelApi configuration initializer
    template "config/propel_api.rb.tt", "config/initializers/propel_api.rb"
    say "Created PropelApi configuration with your selected options", :green
  end
end

#extract_generator_for_customizationObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/generators/propel_api/install/install_generator.rb', line 96

def extract_generator_for_customization
  generator_path = "lib/generators/propel_api"
  
  if File.exist?(generator_path)
    say ""
    say "📦 Generator logic already extracted at #{generator_path}/", :blue
    say "💡 Skipping extraction to preserve your customizations", :cyan
  else
    say ""
    say "📦 Extracting generator logic for full customization...", :blue
    
    # Automatically run the unpack generator to extract generator logic
    invoke PropelApi::UnpackGenerator, [], { force: false }
    
    say ""
    say "✅ Generator logic extracted to lib/generators/propel_api/", :green
    say "💡 Your application is now completely standalone - no gem dependency needed for generators!", :cyan
    say "🗑️  You can now remove 'propel_api' from your Gemfile", :yellow
  end
end

#show_setup_instructionsObject



92
93
94
# File 'lib/generators/propel_api/install/install_generator.rb', line 92

def show_setup_instructions
  say_setup_instructions
end