guard-compat 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72fc80357bae89d7e82328112be553116b9eaab8
|
4
|
+
data.tar.gz: 6210ef62aaae9ffea55f758b46e9bef0eaf5e5d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0248a509ecf2c2d5e90e10bb74ce4ebedff29d2e241cf681224be16e38a41a9245c0849f257afa81ae0c8d5700a066c2bc2af9c9e42b8361decdb31292edee9
|
7
|
+
data.tar.gz: fdf358f5c04db54e00e6ff4c3edaf9a24531377e64cfd7be42942bcb676fce98d620c1d4ede17d639cb5eb7b211d32ae19863dcb867e4d131fffddb1494d20f4
|
data/lib/guard/compat/example.rb
CHANGED
data/lib/guard/compat/plugin.rb
CHANGED
@@ -36,6 +36,22 @@ module Guard
|
|
36
36
|
Guard::Watcher.match_files(plugin, files).uniq
|
37
37
|
end
|
38
38
|
|
39
|
+
def self.watched_directories
|
40
|
+
unless Guard.const_defined?('CLI')
|
41
|
+
msg = 'either Guard has not been required or you did not' \
|
42
|
+
' stub this method in your plugin tests'
|
43
|
+
fail NotImplementedError, msg
|
44
|
+
end
|
45
|
+
|
46
|
+
if Guard.respond_to?(:state)
|
47
|
+
# TODO: the new version is temporary
|
48
|
+
Guard.state.session.watchdirs.map { |d| Pathname(d) }
|
49
|
+
else
|
50
|
+
dirs = Array(Guard.options(:watchdir))
|
51
|
+
dirs.empty? ? [Pathname.pwd] : dirs.map { |d| Pathname(d) }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
39
55
|
module UI
|
40
56
|
def self.color(text, *colors)
|
41
57
|
Guard::UI.send(:color, text, *colors)
|
@@ -54,15 +70,15 @@ module Guard
|
|
54
70
|
end
|
55
71
|
|
56
72
|
def self.error(message, options = {})
|
57
|
-
Guard::UI.
|
73
|
+
Guard::UI.error(message, options)
|
58
74
|
end
|
59
75
|
|
60
76
|
def self.debug(message, options = {})
|
61
|
-
Guard::UI.
|
77
|
+
Guard::UI.debug(message, options)
|
62
78
|
end
|
63
79
|
|
64
80
|
def self.deprecation(message, options = {})
|
65
|
-
Guard::UI.
|
81
|
+
Guard::UI.deprecation(message, options)
|
66
82
|
end
|
67
83
|
|
68
84
|
def self.notify(message, options = {})
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Guard
|
2
|
+
module Compat
|
3
|
+
module Test
|
4
|
+
class Template
|
5
|
+
class Session
|
6
|
+
class MultipleGuardNotImplemented < NotImplementedError
|
7
|
+
def message
|
8
|
+
'multiple guards not supported!'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class GlobalWatchesNotImplemented < NotImplementedError
|
13
|
+
def message
|
14
|
+
'global watches not supported!'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(path, content)
|
19
|
+
@watches = {}
|
20
|
+
@current = nil
|
21
|
+
instance_eval(content, path, 1)
|
22
|
+
end
|
23
|
+
|
24
|
+
def match(file)
|
25
|
+
_watches.map do |expr, block|
|
26
|
+
next unless (match = file.match(expr))
|
27
|
+
block.nil? ? [file] : block.call([file] + match.captures)
|
28
|
+
end.flatten.compact.uniq
|
29
|
+
end
|
30
|
+
|
31
|
+
def guard(name, _options = {})
|
32
|
+
@current = name
|
33
|
+
@watches[@current] = []
|
34
|
+
yield
|
35
|
+
@current = nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def watch(expr, &block)
|
39
|
+
@watches[@current] << [expr, block]
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def _watches
|
45
|
+
keys = @watches.keys
|
46
|
+
fail ArgumentError, 'no watches!' if keys.empty?
|
47
|
+
fail MultipleGuardNotImplemented if keys.size > 1
|
48
|
+
|
49
|
+
key = keys.first
|
50
|
+
fail GlobalWatchesNotImplemented if key.nil?
|
51
|
+
@watches[key]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def initialize(plugin_class)
|
56
|
+
name = plugin_class.to_s.sub('Guard::', '').downcase
|
57
|
+
path = format('lib/guard/%s/templates/Guardfile', name)
|
58
|
+
content = File.read(path)
|
59
|
+
@session = Session.new(path, content)
|
60
|
+
end
|
61
|
+
|
62
|
+
def changed(file)
|
63
|
+
@session.match(file)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/guard/compat/version.rb
CHANGED
@@ -43,6 +43,7 @@ RSpec.describe Guard::MyPlugin, exclude_stubs: [Guard::Plugin] do
|
|
43
43
|
describe '#run_on_modifications' do
|
44
44
|
before do
|
45
45
|
allow(Guard::Compat).to receive(:matching_files)
|
46
|
+
allow(Guard::Compat).to receive(:watched_directories)
|
46
47
|
end
|
47
48
|
|
48
49
|
before { subject.run_on_modifications }
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'guard/compat/test/template'
|
2
|
+
|
3
|
+
require 'guard/compat/example'
|
4
|
+
|
5
|
+
RSpec.describe Guard::MyPlugin do
|
6
|
+
describe 'template' do
|
7
|
+
subject { Guard::Compat::Test::Template.new(described_class) }
|
8
|
+
|
9
|
+
# Stub the template, because we are testing the helper, not the plugin
|
10
|
+
let(:template_contents) do
|
11
|
+
<<-EOS
|
12
|
+
guard :myplugin do
|
13
|
+
watch(/(foo).rb/) { |m| "spec/\#{m[1]}_spec.rb" }
|
14
|
+
watch(/bar.rb/)
|
15
|
+
end
|
16
|
+
EOS
|
17
|
+
end
|
18
|
+
|
19
|
+
before do
|
20
|
+
allow(IO).to receive(:read)
|
21
|
+
.with('lib/guard/myplugin/templates/Guardfile')
|
22
|
+
.and_return(template_contents)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'translates changes' do
|
26
|
+
expect(subject.changed('foo.rb')).to eq(['spec/foo_spec.rb'])
|
27
|
+
expect(subject.changed('bar.rb')).to eq(['bar.rb'])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-compat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cezary Baginski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,8 +58,10 @@ files:
|
|
58
58
|
- lib/guard/compat/example.rb
|
59
59
|
- lib/guard/compat/plugin.rb
|
60
60
|
- lib/guard/compat/test/helper.rb
|
61
|
+
- lib/guard/compat/test/template.rb
|
61
62
|
- lib/guard/compat/version.rb
|
62
63
|
- spec/guard/compat/example_spec.rb
|
64
|
+
- spec/guard/compat/example_template_spec.rb
|
63
65
|
- spec/spec_helper.rb
|
64
66
|
homepage: ''
|
65
67
|
licenses:
|
@@ -87,4 +89,5 @@ specification_version: 4
|
|
87
89
|
summary: Tools for developing Guard compatible plugins
|
88
90
|
test_files:
|
89
91
|
- spec/guard/compat/example_spec.rb
|
92
|
+
- spec/guard/compat/example_template_spec.rb
|
90
93
|
- spec/spec_helper.rb
|