Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

allow guards to specify their templates #369

Merged
merged 2 commits into from

4 participants

@schmurfy

I was playing with the idea of embedding the guard in the gem it supports and while it works "guard init" does not because guard expects the guard to live in a separate gem and hardcode its search path.

Why hardcode something that does not need to be ?
Once the guard class has been found no magic should happen to find any related location or files...

What do you think ?

lib/guard/guard.rb
@@ -58,6 +58,11 @@ def initialize(watchers = [], options = {})
@watchers, @options = watchers, options
end
+
+ def self.template(name)
@rymai Owner
rymai added a note

Could you please add inline documentation as for the other methods? Thanks!

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

I think this is a good idea, thank you. WDYT @guard/core-team ?

@netzpirat
Owner

Yes, looks fine from my side.

@schmurfy

documentation added !

The only thing left which is not working is "guard list" but I am sure how to best handle this, except by searching a guard in every gem in path.

lib/guard/guard.rb
@@ -58,6 +58,15 @@ def initialize(watchers = [], options = {})
@watchers, @options = watchers, options
end
+ # Specify the source for the Guardfile template.
+ # Each guard can redefine this method to add its onw logic.
@rymai Owner
rymai added a note

"Each guard" => "Each Guard plugin" (for consistency with the rest of the docs)
"onw" => "own" ;)

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

Thanks for the doc. Regarding guard list, this has nothing to do with this pull-request, right?

@schmurfy

yes... and no ;)
The only reason for this pull request to exists is to be able to embed a guard into another gem, so why not discuss this here further ? ^^
I can create a separate issue to discuss this if you prefer.

@thibaudgg
Owner

All that is fine for me too, thanks! Just by curiosity on which gem do you want to embed Guard?

@schmurfy

https://github.com/schmurfy/eetee
I just did not felt the need to create one more gem for the guard for a project that will most likely be used only be myself ;)

@thibaudgg
Owner

ok nice!

@schmurfy

@rymal I forgot to say but I did the changes to the documentation.

@rymai
Owner

Wow, I was sure I had left a comment yesterday... Anyways, yes please open a new issue for your specific need.

Thank you for this pull-request, merging it now!

@rymai rymai merged commit 907e34c into guard:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 1 deletion.
  1. +10 −1 lib/guard/guard.rb
View
11 lib/guard/guard.rb
@@ -58,6 +58,15 @@ def initialize(watchers = [], options = {})
@watchers, @options = watchers, options
end
+ # Specify the source for the Guardfile template.
+ # Each Guard plugin can redefine this method to add its own logic.
+ #
+ # @param [String] The plugin name
+ #
+ def self.template(name)
+ File.read("#{ ::Guard.locate_guard(name) }/lib/guard/#{ name }/templates/Guardfile")
+ end
+
# Initialize the Guard plugin. This will copy the Guardfile template inside the Guard plugin gem.
# The template Guardfile must be located within the Gem at `lib/guard/guard-name/templates/Guardfile`.
#
@@ -68,7 +77,7 @@ def self.init(name)
::Guard::UI.info "Guardfile already includes #{ name } guard"
else
content = File.read('Guardfile')
- guard = File.read("#{ ::Guard.locate_guard(name) }/lib/guard/#{ name }/templates/Guardfile")
+ guard = template(name)
File.open('Guardfile', 'wb') do |f|
f.puts(content)
Something went wrong with that request. Please try again.