-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Make the install generator idempotent #2472
Make the install generator idempotent #2472
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Two small suggestions, otherwise 👍
@@ -4,6 +4,8 @@ | |||
|
|||
module Spree | |||
class InstallGenerator < Rails::Generators::Base | |||
SPREE_MOUNT_ROUTE = "mount Spree::Core::Engine" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already namespaced within Spree::
, so I'm not sure that's descriptive. It could be MOUNT_ROUTE
or ENGINE_MOUNT_ROUTE
or CORE_MOUNT_ROUTE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
insert_into_file File.join('config', 'routes.rb'), after: "Rails.application.routes.draw do\n" do | ||
<<-ROUTES | ||
routes_file_path = File.join('config', 'routes.rb') | ||
unless File.read(routes_file_path).match Regexp.new(SPREE_MOUNT_ROUTE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Treating SPREE_MOUNT_ROUTE
as a regex is going to work fine because it doesn't have any regex characters (*
, (
, .
, etc), but it feels like the wrong thing to do.
This should probably be
File.read(routes_file_path).include?(SPREE_MOUNT_ROUTE)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check
Currently if you run the install generator a second time the mount Spree::Core::Engine route gets injected a second time. Thor's insert_into_file should be an reversible operation but I guess because we inject multiple lines into the routes file it doesn't work as expected.
c88077f
to
7ed23ee
Compare
@jhawthorn thanks. Addressed your concerns. |
Currently if you run the install generator a second time the
route gets injected a second time.
Thor's insert_into_file should be an reversible operation but
I guess because we inject multiple lines into the routes file
it doesn't work as expected.