Skip to content

Commit

Permalink
allow requiring from Gemfile to work
Browse files Browse the repository at this point in the history
  • Loading branch information
e2 committed Dec 6, 2014
1 parent ffdc254 commit 747f463
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,27 @@ And then execute:

## Usage

Put the following notes in your plugin file (e.g. `lib/guard/myplugin.rb`):
Put the following in your plugin files (e.g. `lib/guard/myplugin.rb`):

```ruby
# Do NOT require "guard/plugin" - it should already required
# by Guard or by the test helper
# Don't require "guard/plugin" in hits files
require 'guard/compat/plugin'

module Guard
class MyPlugin < Plugin
# (...)
end
end

```

### IMPORTANT

1) Do not include *any* files from Guard directly (if you need something from Guard which Guard::Compat doesn't provide, file an issue)
2) include 'guard/compat/plugin' is *all* your files which use `Guard::Plugin`
3) make sure you include the `< Plugin` part in *every* file which add classes or methods to your plugin class (important if your plugin consists of multiple files/sub class)


And in your plugin tests (e.g. `spec/lib/guard/myplugin_spec.rb`):

```ruby
Expand Down
11 changes: 11 additions & 0 deletions lib/guard/compat/plugin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
unless Object.const_defined?('Guard::Plugin')
# Provided empty definition so requiring the plugin without Guard won't crash
# (e.g. when added to a Gemfile without `require: false`)
module Guard
class Plugin
def initialize
fail NotImplementedError
end
end
end
end
3 changes: 3 additions & 0 deletions lib/guard/compat/test/helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Minimal stub allowing a plugin to work

require 'guard/compat/plugin'

module Guard
class Plugin
attr_reader :options
Expand Down

0 comments on commit 747f463

Please sign in to comment.