Skip to content

Commit 35697ed

Browse files
committed
Detect of phlex-rails is installed before trying to install it
1 parent eaab209 commit 35697ed

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/generators/superform/install/install_generator.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
require "bundler"
2+
13
class Superform::InstallGenerator < Rails::Generators::Base
24
source_root File.expand_path("templates", __dir__)
35

46
APPLICATION_CONFIGURATION_PATH = Rails.root.join("config/application.rb")
57

68
def install_phlex_rails
9+
return if gem_in_bundle? "phlex-rails"
10+
711
gem "phlex-rails"
812
generate "phlex:install"
913
end
@@ -21,4 +25,9 @@ def autoload_components
2125
def create_application_form
2226
template "application_form.rb", Rails.root.join("app/views/forms/application_form.rb")
2327
end
28+
29+
private
30+
def gem_in_bundle?(gem_name)
31+
Bundler.load.specs.any? { |spec| spec.name == gem_name }
32+
end
2433
end

0 commit comments

Comments
 (0)