Skip to content

Commit 42056d5

Browse files
author
Matthew Saginario
committed
added existing_rails_app method and logic
1 parent e3b5b67 commit 42056d5

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

ruby/rails-hyperstack/lib/generators/hyperstack/install_generator.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def report
185185
private
186186

187187
def skip_adding_component?
188-
options['hotloader-only'] || options['webpack-only'] || options['hyper-model-only']
188+
options['hotloader-only'] || options['webpack-only'] || options['hyper-model-only'] || existing_rails_app?
189189
end
190190

191191
def skip_hotloader?
@@ -200,6 +200,23 @@ def skip_hyper_model?
200200
options['hotloader-only'] || options['webpack-only'] || options['skip-hyper-model']
201201
end
202202

203+
def existing_rails_app?
204+
#check to see if there are any routes set up
205+
route_file = File.join('config', 'routes.rb')
206+
207+
count = File.foreach(route_file).inject(0) do | c, line |
208+
line = line.strip
209+
210+
if line.empty? || line.start_with?('#') || line.start_with?('mount')
211+
c
212+
else
213+
c + 1
214+
end
215+
end
216+
217+
count >= 3
218+
end
219+
203220
def inject_into_initializer(s)
204221
file_name = File.join('config', 'initializers', 'hyperstack.rb')
205222
if File.exists?(file_name)

0 commit comments

Comments
 (0)