Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an error message during 'administrate' initialize when there are no models in db. #1782

Merged
merged 24 commits into from
Oct 31, 2020
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
77406aa
Added warning is no database models exist
RaeRachael Oct 5, 2020
559c693
Added new error message, for when there is no 'model' in rails app. db.
KOlofinmoyin Oct 5, 2020
0590000
Update Error message, escape install generator if no models found
RaeRachael Oct 6, 2020
1e45d4e
Moving exit to correct location
RaeRachael Oct 6, 2020
5aa6786
Only run generator if models are found
RaeRachael Oct 6, 2020
f5d7a90
Removing whitespace
RaeRachael Oct 6, 2020
0661292
Load models to test against
RaeRachael Oct 6, 2020
1a0b137
Raising an error agianst no models
RaeRachael Oct 8, 2020
bbfe231
puts message to check databse_models works
RaeRachael Oct 8, 2020
b5be340
Checking database models
RaeRachael Oct 9, 2020
0608cee
sperate w/o tables and unnamed
RaeRachael Oct 9, 2020
f2c0f50
Check warning appears
RaeRachael Oct 9, 2020
db3d25a
Using IOError
RaeRachael Oct 9, 2020
416bf59
Attempt with say_status
RaeRachael Oct 9, 2020
62f75b8
say_status
RaeRachael Oct 9, 2020
7fa1a26
say_status
RaeRachael Oct 9, 2020
26b2603
Passing local rspec
RaeRachael Oct 15, 2020
b749fde
getting visiblitity on why no warning appeared
RaeRachael Oct 15, 2020
4f714fb
fixing stilly error
RaeRachael Oct 15, 2020
e37010b
suggest deleting administrate-controller
RaeRachael Oct 19, 2020
d00fd41
reject unnamed
RaeRachael Oct 19, 2020
31b7e9b
Removing visibility for testing, moved warning to last output
RaeRachael Oct 19, 2020
efa94d0
Turn output messsage into a warning
RaeRachael Oct 29, 2020
158e2c5
Removing Whitespace
RaeRachael Oct 31, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions lib/generators/administrate/install/install_generator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
if defined?(Zeitwerk)
Zeitwerk::Loader.eager_load_all
else
Rails.application.eager_load!
end

require "rails/generators/base"
require "administrate/generator_helpers"
require "administrate/namespace"
Expand Down Expand Up @@ -31,6 +37,12 @@ def run_dashboard_generators
end
end

def model_check
if valid_dashboard_models.none?
puts "WARNING: Add models before installing Administrate."
end
end

private

def namespace
Expand All @@ -44,6 +56,30 @@ def singular_dashboard_resources
def dashboard_resources
Administrate::Namespace.new(namespace).resources
end

def valid_dashboard_models
database_models - invalid_dashboard_models
end

def database_models
ActiveRecord::Base.descendants.reject(&:abstract_class?)
end

def invalid_dashboard_models
(models_without_tables + namespaced_models + unnamed_constants).uniq
end

def models_without_tables
database_models.reject(&:table_exists?)
end

def namespaced_models
database_models.select { |model| model.to_s.include?("::") }
end

def unnamed_constants
ActiveRecord::Base.descendants.reject { |d| d.name == d.to_s }
end
end
end
end