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

Make the install generator idempotent #2472

Merged
merged 1 commit into from
Jan 2, 2018

Conversation

tvdeyen
Copy link
Member

@tvdeyen tvdeyen commented Dec 22, 2017

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.

Copy link
Contributor

@jhawthorn jhawthorn left a 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"
Copy link
Contributor

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

Copy link
Member Author

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)
Copy link
Contributor

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)

Copy link
Member Author

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.
@tvdeyen tvdeyen force-pushed the install-generator-routing-fix branch from c88077f to 7ed23ee Compare December 22, 2017 23:46
@tvdeyen
Copy link
Member Author

tvdeyen commented Dec 22, 2017

@jhawthorn thanks. Addressed your concerns.

@jhawthorn jhawthorn merged commit b7753a4 into solidusio:master Jan 2, 2018
@tvdeyen tvdeyen deleted the install-generator-routing-fix branch July 10, 2021 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants