Skip to content

Comment out optional gems#3224

Merged
mrcasals merged 1 commit intomasterfrom
comment_out_optional_gems
Apr 16, 2018
Merged

Comment out optional gems#3224
mrcasals merged 1 commit intomasterfrom
comment_out_optional_gems

Conversation

@josepjaume
Copy link
Copy Markdown
Contributor

🎩 What? Why?

This will comment out optional gems found on the project's Gemfile, in order to indicate to the user they are available, but optional.

So this will generate this gemfile:

source "https://rubygems.org"

ruby RUBY_VERSION

gem "decidim", "0.11.0.pre"
# gem "decidim-consultations", "0.11.0.pre"

gem "puma", "~> 3.0"
gem "uglifier", "~> 4.1"

gem "faker", "~> 1.8"

group :development, :test do
  gem "byebug", "~> 10.0", platform: :mri

  gem "decidim-dev", "0.11.0.pre"
end

group :development do
  gem "letter_opener_web", "~> 1.3"
  gem "listen", "~> 3.1"
  gem "spring", "~> 2.0"
  gem "spring-watcher-listen", "~> 2.0"
  gem "web-console", "~> 3.5"
end

When given a gemfile like this:

source "https://rubygems.org"

ruby RUBY_VERSION

gem "decidim", path: "."
gem "decidim-consultations", path: "decidim-consultations"

gem "puma", "~> 3.0"
gem "uglifier", "~> 4.1"

gem "faker", "~> 1.8"

group :development, :test do
  gem "byebug", "~> 10.0", platform: :mri

  gem "decidim-dev", path: "."
end

group :development do
  gem "letter_opener_web", "~> 1.3"
  gem "listen", "~> 3.1"
  gem "spring", "~> 2.0"
  gem "spring-watcher-listen", "~> 2.0"
  gem "web-console", "~> 3.5"
end

📌 Related Issues

None

📋 Subtasks

None

📷 Screenshots (optional)

None

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

What about explicitly commenting out the optional gems? I think it's slightly less obscure.

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

There's another option which is directly commenting out decidim-consultations in the main repo Gemfile. The gem would still be used for local development, but not in the rest of the cases.

But that would mean relying on a what I think is a bundler's bug, so let's not do that 🤣

@josepjaume
Copy link
Copy Markdown
Contributor Author

Exactly @deivid-rodriguez, I wanted to avoid relying on a bug, doesn't sound safe xDDD. Also the development_app didn't seem to play nice with it. So do you like this approach then?

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

deivid-rodriguez commented Apr 16, 2018

Yes, I was thinking about a less DRY but more explicit approach, like

 gsub_file "Gemfile", /gem "decidim-consultations".*/, "# gem \"decidim-consultations\", #{gem_modifier}" if current_gem == "decidim"

But what you're doing here sounds good too!

@josepjaume
Copy link
Copy Markdown
Contributor Author

Let's see if we hit a wall with my approach. It's a bit more magical but it's useful and kinda low-friction too.

@mrcasals mrcasals merged commit 260b903 into master Apr 16, 2018
@mrcasals mrcasals deleted the comment_out_optional_gems branch April 16, 2018 13:57
@deivid-rodriguez
Copy link
Copy Markdown
Contributor

deivid-rodriguez commented Apr 16, 2018

Arrived late to the party but I think this is going to break external plugin test app Gemfile generation. When you have an external plugin, you usually want a Gemfile where the plugin being developed is uncommented and points to the local path of the plugin.

For example, this is how the test app Gemfile looks in the decidim-votings plugin:

# frozen_string_literal: true

source "https://rubygems.org"

ruby RUBY_VERSION

gem "decidim", git: "https://github.com/decidim/decidim", branch: "master"
gem "decidim-votings", path: ".."

gem "puma", "~> 3.0"
gem "uglifier", "~> 4.1"

group :development, :test do
  gem "byebug", "~> 10.0", platform: :mri

  gem "decidim-dev", git: "https://github.com/decidim/decidim", branch: "master"
end

group :development do
  gem "faker", "~> 1.8"
  gem "letter_opener_web", "~> 1.3"
  gem "listen", "~> 3.1"
  gem "spring", "~> 2.0"
  gem "spring-watcher-listen", "~> 2.0"
  gem "web-console", "~> 3.5"
end

With this patch, the Gemfile will have the gem commented out and thus break its tests.

I think we need to go with my explicit approach...

@josepjaume
Copy link
Copy Markdown
Contributor Author

😢 😢 😢 😢 😢 😢

@josepjaume
Copy link
Copy Markdown
Contributor Author

@deivid-rodriguez I'm afraid this will still happen if you happen to include decidim-consultations in your third-party project, in case you depend on it.

I have a funny idea, let me open a PR 😆

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

No, because it's scoped to current_gem == "decidim"

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

deivid-rodriguez commented Apr 16, 2018

The current_gem method basically inspects the gemspec and tries to guess what kind of thing you are developing. I think 2f9d46a should work...

@josepjaume
Copy link
Copy Markdown
Contributor Author

Oh, but shouldn't my approach work if I scope it to current_gem == "decidim" as well? I think I'm a bit lost here...

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

Yeah, that should work too.

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

My problem with this approach is that it's a bit hard to understand. First time I read the code I thought, why are you matching # decidim-dev? decidim-dev is not commented out in the Gemfile... 🤔. The answer is that the previous line is commenting it out, so you need to undo that, but it's not straightforward in my opinion.

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

@josepjaume Just a friendly remainder about this, so we don't forget to fix it before 0.11! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants