guard-yield 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +14 -0
- data/Guardfile +48 -0
- data/LICENSE.txt +21 -0
- data/README.md +147 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/guard-yield.gemspec +25 -0
- data/lib/guard/yield.rb +32 -0
- data/lib/guard/yield/templates/Guardfile +29 -0
- data/lib/guard/yield/version.rb +8 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 60a538e31149860b0a0877b63fe892f945c849c0
|
4
|
+
data.tar.gz: dca6f2aa3c6fa7643493a183da8d1fe5303a9542
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 01ce9fbc2d6418571b950b7cb54724d29728ae753c459d89b254b61c052482e3d4561ea5a7732a9bda83cb299ec5e8ae9fa1cda15632c746ef23723766ab2740
|
7
|
+
data.tar.gz: 788d76725ca9801c5d93cb2c24d7813a2ef682a21ddc018ee0ace63530c1db1c034b3331d456a385da50628d6827f96f6f8e6f501331855cacde977c7b127867
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in guard-yield.gemspec
|
4
|
+
gemspec development_group: :gem_build_tools
|
5
|
+
|
6
|
+
group :development do
|
7
|
+
gem 'guard'
|
8
|
+
gem 'guard-rspec', '~> 4.5', '>= 4.5.2'
|
9
|
+
end
|
10
|
+
|
11
|
+
group :gem_build_tools do
|
12
|
+
gem "rake", "~> 10.0"
|
13
|
+
gem "rspec", "~> 3.2"
|
14
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features)
|
6
|
+
|
7
|
+
## Uncomment to clear the screen before every task
|
8
|
+
# clearing :on
|
9
|
+
|
10
|
+
## Guard internally checks for changes in the Guardfile and exits.
|
11
|
+
## If you want Guard to automatically start up again, run guard in a
|
12
|
+
## shell loop, e.g.:
|
13
|
+
##
|
14
|
+
## $ while bundle exec guard; do echo "Restarting Guard..."; done
|
15
|
+
##
|
16
|
+
## Note: if you are using the `directories` clause above and you are not
|
17
|
+
## watching the project directory ('.'), then you will want to move
|
18
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
19
|
+
#
|
20
|
+
# $ mkdir config
|
21
|
+
# $ mv Guardfile config/
|
22
|
+
# $ ln -s config/Guardfile .
|
23
|
+
#
|
24
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
25
|
+
|
26
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
27
|
+
# rspec may be run, below are examples of the most common uses.
|
28
|
+
# * bundler: 'bundle exec rspec'
|
29
|
+
# * bundler binstubs: 'bin/rspec'
|
30
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
31
|
+
# installed the spring binstubs per the docs)
|
32
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
33
|
+
# * 'just' rspec: 'rspec'
|
34
|
+
|
35
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
36
|
+
require "guard/rspec/dsl"
|
37
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
38
|
+
|
39
|
+
# RSpec files
|
40
|
+
rspec = dsl.rspec
|
41
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
42
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
43
|
+
watch(rspec.spec_files)
|
44
|
+
|
45
|
+
# Ruby files
|
46
|
+
ruby = dsl.ruby
|
47
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
48
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Cezary Baginski
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
# Guard::Yield
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/e3/guard-yield.png?branch=master)](https://travis-ci.org/e2/guard-yield)
|
4
|
+
[![Gem Version](http://img.shields.io/gem/v/guard-yield.svg)](http://badge.fury.io/rb/guard-yield)
|
5
|
+
e
|
6
|
+
|
7
|
+
A Guard pseudo-plugin to conveniently run *any* Ruby code - straight from your
|
8
|
+
Guardfile (without writing your own plugin).
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
in your Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
group :development do
|
16
|
+
gem 'guard-yield'
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
Install with:
|
21
|
+
|
22
|
+
$ bundle install
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install guard-yield
|
27
|
+
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
Add snippets to your `Guardfile` with:
|
32
|
+
|
33
|
+
$ bundle exec guard init yield
|
34
|
+
|
35
|
+
Then, edit/remove them and run:
|
36
|
+
|
37
|
+
$ bundle exec guard
|
38
|
+
|
39
|
+
## Quick example
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
md5_summer = proc { |_, _, files| puts `md5sum #{files * ' '}` }
|
43
|
+
guard :yield, run_on_modifications: md5_summer do
|
44
|
+
watch('foo.rb')
|
45
|
+
watch('bar.rb')
|
46
|
+
watch('baz.rb')
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
Yes, you don't need to resort to hax with the `watch()` block or creating
|
51
|
+
inline Guard plugins in your Guardfile. Especially for local one-shot pieces of
|
52
|
+
code like this.
|
53
|
+
|
54
|
+
## Tips
|
55
|
+
|
56
|
+
Aside from supporting all the methods for Guard::Plugin:
|
57
|
+
|
58
|
+
```
|
59
|
+
:start
|
60
|
+
:stop
|
61
|
+
:run_all
|
62
|
+
:reload
|
63
|
+
:run_on_additions
|
64
|
+
:run_on_modifications
|
65
|
+
:run_on_removals
|
66
|
+
:run_on_changes
|
67
|
+
```
|
68
|
+
|
69
|
+
there's a special `:object` option, that allows you to pass any object you like
|
70
|
+
to *all* the methods.
|
71
|
+
|
72
|
+
(Just check the logger example in the Guardfile).
|
73
|
+
|
74
|
+
This means you can conveniently use any Ruby library inside your Guardfile -
|
75
|
+
without writing a Guard plugin as a wrapper for it.
|
76
|
+
|
77
|
+
Also, remember to use Guard's `throw(:task_has_failed)` to flag an error
|
78
|
+
(otherwise Guard will disable your guard), e.g. :
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
my_syntax_checker = proc do |_, _, changes|
|
82
|
+
changes.each do |file|
|
83
|
+
system("ruby -c #{file}") || throw(:task_has_failed) # IMPORTANT!
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
guard :yield, run_on_modifications: &my_syntax_checker do
|
88
|
+
watch('foo.rb')
|
89
|
+
watch('bar.rb')
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
93
|
+
|
94
|
+
## FAQ
|
95
|
+
|
96
|
+
> "Why not use the watch() block for running code?"
|
97
|
+
|
98
|
+
1. That's not what it's for (you need the `return nil` hack at least)
|
99
|
+
2. You don't have access to the guard object (even if it's your own)
|
100
|
+
3. You can't pass data to the block (you just have the file)
|
101
|
+
4. The dsl has it's own namespace - guard-yield side-steps that
|
102
|
+
5. This cleanly separates rules (which can get complex) from behavior
|
103
|
+
6. It really is just for substituting one change for another (not for code)
|
104
|
+
|
105
|
+
Here's an example anyway (NOT RECOMMENDED!):
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
# nil to prevent plugin for doing anything itself
|
109
|
+
watch("foo.*") { |m| `cp #{m} #{m}.backup`; nil }
|
110
|
+
```
|
111
|
+
|
112
|
+
> "Why not use an inline Guard plugin inside the Guardfile?"
|
113
|
+
|
114
|
+
Usually it's the Object-Oriented way to do things, and it's likely easier to
|
115
|
+
extract into a gem.
|
116
|
+
|
117
|
+
But if you don't want to create a full-blown gem, or you want the logic to be
|
118
|
+
local, verbose and concise ... guard-yield will help.
|
119
|
+
|
120
|
+
And as above - guard-yield allows you to prototype an interface to any Ruby
|
121
|
+
library and use that directly in your Guardfile - and often with less code,
|
122
|
+
classes and methods to get the job done.
|
123
|
+
|
124
|
+
> "Why not just create a gem/lib for every task like that?"
|
125
|
+
|
126
|
+
One reason is - you may quickly end up with too many gems to maintain (for no
|
127
|
+
reason), while those gems will just be a thin, minimal front-end to a complex
|
128
|
+
Ruby library.
|
129
|
+
|
130
|
+
Basically it all boils down to how many options you want your guard plugin to
|
131
|
+
handle - and how complex handling them is.
|
132
|
+
|
133
|
+
Not every use case can be extracted into a nice generic gem useful for many
|
134
|
+
people - that's why I created this gem.
|
135
|
+
|
136
|
+
Have fun!
|
137
|
+
|
138
|
+
|
139
|
+
## Contributing
|
140
|
+
|
141
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/guard-yield.
|
142
|
+
|
143
|
+
|
144
|
+
## License
|
145
|
+
|
146
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
147
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "guard/yield"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/guard-yield.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'guard/yield/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "guard-yield"
|
8
|
+
spec.version = Guard::Yield::VERSION
|
9
|
+
spec.authors = ["Cezary Baginski"]
|
10
|
+
spec.email = ["cezary@chronomantic.net"]
|
11
|
+
|
12
|
+
spec.summary = %q{Guard plugin for running custom Ruby code}
|
13
|
+
spec.description = %q{This plugin allows you to run any Ruby code within Guard - without writing your own plugin}
|
14
|
+
spec.homepage = "https://github.com/guard/guard-yield"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency('guard-compat', '~> 1.0')
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
25
|
+
end
|
data/lib/guard/yield.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "guard/compat/plugin"
|
2
|
+
|
3
|
+
module Guard
|
4
|
+
class Yield < Plugin
|
5
|
+
PLUGIN_METHODS = %i(start stop run_all reload run_on_additions
|
6
|
+
run_on_modifications run_on_removals run_on_changes)
|
7
|
+
|
8
|
+
VALID_GUARD_OPTIONS = %i(watchers group callbacks)
|
9
|
+
|
10
|
+
VALID_OPTIONS = %i(object)
|
11
|
+
|
12
|
+
def initialize(options={})
|
13
|
+
valid_options = PLUGIN_METHODS + VALID_OPTIONS + VALID_GUARD_OPTIONS
|
14
|
+
options.keys.each do |key|
|
15
|
+
unless valid_options.include?(key)
|
16
|
+
raise ArgumentError, "Unknown option: #{key.inspect}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
PLUGIN_METHODS.each do |name|
|
24
|
+
define_method(name) do |*args|
|
25
|
+
block = self.options.fetch(name, nil)
|
26
|
+
next unless block
|
27
|
+
object = self.options.fetch(:object, self)
|
28
|
+
block.call object, name, *args
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Example 1: Run a single command whenever a file is added
|
2
|
+
|
3
|
+
notifier = proc do |title, _, changes|
|
4
|
+
Guard::Notifier.notify(changes * ",", title: title )
|
5
|
+
end
|
6
|
+
|
7
|
+
guard :yield, { run_on_additions: notifier, object: "Add missing specs!" } do
|
8
|
+
watch(/^(.*)\.rb$/) { |m| "spec/#{m}_spec.rb" }
|
9
|
+
end
|
10
|
+
|
11
|
+
# Example 2: log all kinds of changes
|
12
|
+
|
13
|
+
require 'logger'
|
14
|
+
yield_options = {
|
15
|
+
object: ::Logger.new(STDERR), # passed to every other call
|
16
|
+
|
17
|
+
start: proc { |logger| logger.level = Logger::INFO },
|
18
|
+
stop: proc { |logger| logger.info "Guard::Yield - Done!" },
|
19
|
+
|
20
|
+
run_on_modifications: proc { |log, _, files| log.info "!! #{files * ','}" },
|
21
|
+
run_on_additions: proc { |log, _, files| log.warn "++ #{files * ','}" },
|
22
|
+
run_on_removals: proc { |log, _, files| log.error "xx #{files * ','}" },
|
23
|
+
}
|
24
|
+
|
25
|
+
guard :yield, yield_options do
|
26
|
+
watch(/^(.*)\.css$/)
|
27
|
+
watch(/^(.*)\.jpg$/)
|
28
|
+
watch(/^(.*)\.png$/)
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-yield
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cezary Baginski
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: guard-compat
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
description: This plugin allows you to run any Ruby code within Guard - without writing
|
42
|
+
your own plugin
|
43
|
+
email:
|
44
|
+
- cezary@chronomantic.net
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".rspec"
|
51
|
+
- ".travis.yml"
|
52
|
+
- Gemfile
|
53
|
+
- Guardfile
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- bin/console
|
58
|
+
- bin/setup
|
59
|
+
- guard-yield.gemspec
|
60
|
+
- lib/guard/yield.rb
|
61
|
+
- lib/guard/yield/templates/Guardfile
|
62
|
+
- lib/guard/yield/version.rb
|
63
|
+
homepage: https://github.com/guard/guard-yield
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.4.5
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Guard plugin for running custom Ruby code
|
87
|
+
test_files: []
|