spicycode-beholder 0.5.4 → 0.5.5
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.
- data/README.textile +4 -2
- data/Rakefile +36 -58
- data/bin/beholder +1 -1
- data/examples/example_helper.rb +5 -2
- data/examples/lib/beholder_example.rb +126 -34
- data/lib/beholder.rb +121 -88
- metadata +11 -9
data/README.textile
CHANGED
@@ -52,7 +52,7 @@ map_for(:beholders_lair) do |wizard|
|
|
52
52
|
wizard.keep_a_watchful_eye_for 'coverage'
|
53
53
|
|
54
54
|
# Forget all other treasure maps loaded
|
55
|
-
# wizard.
|
55
|
+
# wizard.clear_maps
|
56
56
|
|
57
57
|
# Add your own rules
|
58
58
|
# wizard.prepare_spell_for /\/foobar/ do
|
@@ -62,4 +62,6 @@ map_for(:beholders_lair) do |wizard|
|
|
62
62
|
# You could set the list of all examples to be run after pressing ctrl-c once
|
63
63
|
# it defaults to any files in examples, spec, and test
|
64
64
|
wizard.all_examples = Dir['your/path/**/*_here.rb']
|
65
|
-
end
|
65
|
+
end
|
66
|
+
|
67
|
+
Treasure maps are automatically reloaded when you change them, so you can fire up Beholder and start iterating on the config live.
|
data/Rakefile
CHANGED
@@ -1,66 +1,44 @@
|
|
1
|
-
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
s.has_rdoc = true
|
19
|
-
s.extra_rdoc_files = ["README.textile", "LICENSE", 'TODO']
|
20
|
-
s.summary = SUMMARY
|
21
|
-
s.description = s.summary
|
22
|
-
s.author = AUTHOR
|
23
|
-
s.email = EMAIL
|
24
|
-
s.homepage = HOMEPAGE
|
25
|
-
s.add_dependency "fsevents"
|
26
|
-
s.bindir = 'bin'
|
27
|
-
s.default_executable = 'beholder'
|
28
|
-
s.executables = ["beholder"]
|
29
|
-
s.require_path = 'lib'
|
30
|
-
s.autorequire = GEM
|
31
|
-
s.files = %w(LICENSE README.textile Rakefile TODO) + Dir.glob("{lib,examples}/**/*")
|
32
|
-
end
|
33
|
-
|
34
|
-
Rake::GemPackageTask.new(spec) do |pkg|
|
35
|
-
pkg.gem_spec = spec
|
36
|
-
end
|
37
|
-
|
38
|
-
desc "install the gem locally"
|
39
|
-
task :install => [:package] do
|
40
|
-
sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
|
41
|
-
end
|
42
|
-
|
43
|
-
desc "create a gemspec file"
|
44
|
-
task :make_gemspec do
|
45
|
-
File.open("#{GEM}.gemspec", "w") do |file|
|
46
|
-
file.puts spec.to_ruby
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |s|
|
4
|
+
s.name = "beholder"
|
5
|
+
s.summary = "An ancient beholder that watches your treasure, and deals with thiefs"
|
6
|
+
s.email = "chad@spicycode.com, rsanheim@gmail.com"
|
7
|
+
s.homepage = "http://github.com/rsanheim/beholder"
|
8
|
+
s.description = "beholder"
|
9
|
+
s.authors = "Chad Humphries, Rob Sanheim"
|
10
|
+
s.has_rdoc = true
|
11
|
+
s.extra_rdoc_files = ["README.textile", "LICENSE", 'TODO']
|
12
|
+
s.add_dependency "fsevents"
|
13
|
+
s.bindir = 'bin'
|
14
|
+
s.default_executable = 'beholder'
|
15
|
+
s.executables = ["beholder"]
|
16
|
+
s.require_path = 'lib'
|
17
|
+
s.files = %w(LICENSE README.textile Rakefile TODO) + Dir.glob("{lib,examples}/**/*")
|
47
18
|
end
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
48
21
|
end
|
49
22
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
23
|
+
begin
|
24
|
+
gem "spicycode-micronaut"
|
25
|
+
require 'micronaut/rake_task'
|
54
26
|
|
55
|
-
|
56
|
-
|
57
|
-
desc "Run all micronaut examples using rcov"
|
58
|
-
Micronaut::RakeTask.new :coverage do |t|
|
27
|
+
desc "Run all micronaut examples"
|
28
|
+
Micronaut::RakeTask.new :examples do |t|
|
59
29
|
t.pattern = "examples/**/*_example.rb"
|
60
|
-
t.rcov = true
|
61
|
-
t.rcov_opts = "--exclude \"examples/*,gems/*,db/*,/Library/Frameworks/*,/Library/Ruby/*,config/*\" --text-summary --sort coverage --no-validator-links"
|
62
30
|
end
|
63
31
|
|
64
|
-
|
32
|
+
namespace :examples do
|
33
|
+
desc "Run all micronaut examples using rcov"
|
34
|
+
Micronaut::RakeTask.new :coverage do |t|
|
35
|
+
t.pattern = "examples/**/*_example.rb"
|
36
|
+
t.rcov = true
|
37
|
+
t.rcov_opts = "--exclude \"examples/*,gems/*,db/*,/Library/Frameworks/*,/Library/Ruby/*,config/*\" --text-summary --sort coverage --no-validator-links"
|
38
|
+
end
|
39
|
+
end
|
65
40
|
|
66
|
-
task :default => 'examples:coverage'
|
41
|
+
task :default => 'examples:coverage'
|
42
|
+
rescue LoadError
|
43
|
+
puts "Micronaut required to run examples. Install it with: sudo gem install spicycode-micronaut -s http://gems.github.com"
|
44
|
+
end
|
data/bin/beholder
CHANGED
data/examples/example_helper.rb
CHANGED
@@ -4,7 +4,9 @@ $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
|
|
4
4
|
require 'beholder'
|
5
5
|
require 'rubygems'
|
6
6
|
require 'micronaut'
|
7
|
-
gem :rr, '
|
7
|
+
gem :rr, '>=0.7.0'
|
8
|
+
require 'log_buddy'
|
9
|
+
LogBuddy.init
|
8
10
|
|
9
11
|
def not_in_editor?
|
10
12
|
['TM_MODE', 'EMACS', 'VIM'].all? { |k| !ENV.has_key?(k) }
|
@@ -14,4 +16,5 @@ Micronaut.configure do |c|
|
|
14
16
|
c.formatter = :documentation
|
15
17
|
c.mock_with :rr
|
16
18
|
c.color_enabled = not_in_editor?
|
17
|
-
|
19
|
+
c.filter_run :focused => true
|
20
|
+
end
|
@@ -2,85 +2,177 @@ require File.expand_path(File.dirname(__FILE__) + "/../example_helper")
|
|
2
2
|
|
3
3
|
describe Beholder do
|
4
4
|
|
5
|
-
describe "when
|
5
|
+
describe "when run is called" do
|
6
6
|
|
7
|
-
it "should
|
8
|
-
beholder = stub(Beholder.new) {
|
7
|
+
it "should create a new beholder" do
|
8
|
+
beholder = stub(Beholder.new) { prepare; start }
|
9
9
|
mock(Beholder).new { beholder }
|
10
10
|
|
11
|
-
Beholder.
|
11
|
+
Beholder.run
|
12
12
|
end
|
13
13
|
|
14
|
-
it "should prepare
|
14
|
+
it "should prepare" do
|
15
15
|
beholder = Beholder.new
|
16
|
-
stub(beholder).
|
17
|
-
|
18
|
-
mock(beholder).prepare_for_interlopers
|
16
|
+
stub(beholder).start
|
17
|
+
mock(beholder).prepare
|
19
18
|
stub(Beholder).new { beholder }
|
20
19
|
|
21
|
-
Beholder.
|
20
|
+
Beholder.run
|
22
21
|
end
|
23
22
|
|
24
|
-
it "should
|
23
|
+
it "should start" do
|
25
24
|
beholder = Beholder.new
|
26
|
-
mock(beholder).
|
27
|
-
stub(beholder).
|
28
|
-
stub(beholder).prepare_for_interlopers
|
25
|
+
mock(beholder).start
|
26
|
+
stub(beholder).prepare
|
29
27
|
stub(Beholder).new { beholder }
|
30
28
|
|
31
|
-
Beholder.
|
29
|
+
Beholder.run
|
32
30
|
end
|
33
31
|
|
34
32
|
end
|
35
33
|
|
36
|
-
describe "when it notices
|
34
|
+
describe "when it notices file(s) changed" do
|
37
35
|
|
38
|
-
it "should identify what was
|
39
|
-
|
36
|
+
it "should identify what was changed" do
|
37
|
+
files = ['widgets']
|
40
38
|
beholder = Beholder.new
|
41
|
-
mock(beholder).
|
42
|
-
beholder.
|
39
|
+
mock(beholder).find_matches('widgets') { nil }
|
40
|
+
beholder.on_change files
|
43
41
|
end
|
44
42
|
|
45
|
-
it "should
|
46
|
-
|
43
|
+
it "should run tests for the file that changed" do
|
44
|
+
files = ['widgets']
|
47
45
|
beholder = Beholder.new
|
48
|
-
stub(beholder).
|
49
|
-
mock(beholder).
|
50
|
-
beholder.
|
46
|
+
stub(beholder).find_matches('widgets') { 'widgets_example' }
|
47
|
+
mock(beholder).run_tests(['widgets_example'])
|
48
|
+
beholder.on_change files
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should re-eval the treasure map if the map was modified" do
|
52
|
+
treasure_map = "#{Dir.pwd}/.treasure_map.rb"
|
53
|
+
beholder = Beholder.new
|
54
|
+
stub(File).exist?(treasure_map) { true }
|
55
|
+
mock(beholder).read_map_at(treasure_map)
|
56
|
+
beholder.on_change treasure_map
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "build_cmd" do
|
62
|
+
it "contructs build cmd for a single file" do
|
63
|
+
beholder = Beholder.new
|
64
|
+
beholder.build_cmd(["test/foo_test.rb"]).should == %[ruby -e "%w[test/foo_test].each { |f| require f }"]
|
65
|
+
end
|
66
|
+
|
67
|
+
it "contructs build cmd for a multiple files" do
|
68
|
+
beholder = Beholder.new
|
69
|
+
beholder.build_cmd(["test/foo_test.rb", "test/functionals/foo_test.rb"]).should == %[ruby -e "%w[test/foo_test test/functionals/foo_test].each { |f| require f }"]
|
51
70
|
end
|
52
71
|
|
53
72
|
end
|
54
73
|
|
55
|
-
describe "
|
74
|
+
describe "blink" do
|
56
75
|
|
57
76
|
it "should forget about any interlopers" do
|
58
77
|
beholder = Beholder.new
|
59
78
|
beholder.instance_variable_set("@sent_an_int", true) # Not so hot, but I'm tired
|
60
79
|
|
61
80
|
beholder.sent_an_int.should be_true
|
62
|
-
beholder.blink
|
81
|
+
beholder.__send__ :blink
|
63
82
|
beholder.sent_an_int.should be_false
|
64
83
|
end
|
65
84
|
|
66
85
|
end
|
67
86
|
|
68
|
-
describe "when
|
87
|
+
describe "when shutting down" do
|
69
88
|
|
70
|
-
it "should stop watching for
|
89
|
+
it "should stop watching for changes" do
|
71
90
|
beholder = Beholder.new
|
72
91
|
stub(beholder).exit
|
73
|
-
stub(beholder).
|
74
|
-
beholder.
|
92
|
+
stub(beholder).watcher { mock!.shutdown }
|
93
|
+
beholder.shutdown
|
75
94
|
end
|
76
95
|
|
77
|
-
it "should
|
96
|
+
it "should exit" do
|
78
97
|
beholder = Beholder.new
|
79
|
-
stub(beholder).
|
98
|
+
stub(beholder).watcher { stub!.shutdown }
|
80
99
|
mock(beholder).exit
|
81
|
-
beholder.
|
100
|
+
beholder.shutdown
|
82
101
|
end
|
83
102
|
|
84
103
|
end
|
85
104
|
|
86
|
-
|
105
|
+
describe "watch" do
|
106
|
+
|
107
|
+
it "adds paths to watch" do
|
108
|
+
beholder = Beholder.new
|
109
|
+
beholder.watch "bar", "foo"
|
110
|
+
beholder.paths_to_watch.should == ["bar", "foo"]
|
111
|
+
end
|
112
|
+
|
113
|
+
it "aliases keep_a_watchful_eye_for to watch" do
|
114
|
+
beholder = Beholder.new
|
115
|
+
beholder.keep_a_watchful_eye_for "bar", "foo"
|
116
|
+
beholder.paths_to_watch.should == ["bar", "foo"]
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should uniq and sort the paths" do
|
120
|
+
beholder = Beholder.new
|
121
|
+
beholder.watch "foo", "bar", "specs", "foo", "bar", "bar2"
|
122
|
+
beholder.paths_to_watch.should == ["bar", "bar2", "foo", "specs"]
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "add_mapping" do
|
127
|
+
|
128
|
+
it "adds pattern and block to current_map" do
|
129
|
+
beholder = Beholder.new
|
130
|
+
blk = lambda { "something" }
|
131
|
+
beholder.map_for(:example) { |m| m.add_mapping(%r%example_helper\.rb%, &blk) }
|
132
|
+
beholder.treasure_maps[:example].should == [[ %r%example_helper\.rb%, blk ]]
|
133
|
+
end
|
134
|
+
|
135
|
+
it "aliases prepare_spell_for to add_mapping" do
|
136
|
+
beholder = Beholder.new
|
137
|
+
blk = lambda { "something" }
|
138
|
+
beholder.map_for(:example) { |m| m.prepare_spell_for(%r%example_helper\.rb%, &blk) }
|
139
|
+
beholder.treasure_maps[:example].should == [[ %r%example_helper\.rb%, blk ]]
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "examples_matching" do
|
144
|
+
|
145
|
+
it "finds a fuzzy match from all_examples" do
|
146
|
+
beholder = Beholder.new
|
147
|
+
stub(beholder).all_examples { ["examples/unit/foo_example.rb", "examples/slow/foo_example.rb", "src/foo_system_example.rb", "examples/some/deeper/dir/foo_example.rb"] }
|
148
|
+
beholder.examples_matching("foo").should == ["examples/unit/foo_example.rb", "examples/slow/foo_example.rb", "examples/some/deeper/dir/foo_example.rb"]
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "read_map_at" do
|
153
|
+
|
154
|
+
it "rescues exceptions from instance_eval'ing the map, and carries on" do
|
155
|
+
beholder = Beholder.new
|
156
|
+
stub(File).exist? { true }
|
157
|
+
mock(File).readlines("my_map.rb") { ["!and this is invalid Ruby;end\nand more"] }
|
158
|
+
stub(beholder).puts
|
159
|
+
lambda { beholder.read_map_at("my_map.rb") }.should_not raise_error
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "say" do
|
165
|
+
|
166
|
+
it "puts to stdout if verbose is true" do
|
167
|
+
begin
|
168
|
+
ARGV.push("-v")
|
169
|
+
beholder = Beholder.new
|
170
|
+
mock(beholder).puts("yo dawg")
|
171
|
+
beholder.__send__ :say, "yo dawg"
|
172
|
+
ensure
|
173
|
+
ARGV.pop
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
data/lib/beholder.rb
CHANGED
@@ -2,101 +2,150 @@ require 'rubygems'
|
|
2
2
|
gem :fsevents
|
3
3
|
require 'fsevents'
|
4
4
|
|
5
|
-
class Proc
|
6
|
-
alias :cast! :call
|
7
|
-
end
|
8
|
-
|
9
5
|
class Beholder
|
10
6
|
|
11
|
-
attr_reader :paths_to_watch, :sent_an_int, :mappings, :working_directory, :
|
12
|
-
attr_reader :
|
7
|
+
attr_reader :paths_to_watch, :sent_an_int, :mappings, :working_directory, :verbose
|
8
|
+
attr_reader :watcher, :treasure_maps, :possible_map_locations, :all_examples
|
13
9
|
|
14
10
|
def initialize
|
11
|
+
@working_directory = Dir.pwd
|
15
12
|
@paths_to_watch, @all_examples = [], []
|
16
13
|
@mappings, @treasure_maps = {}, {}
|
17
14
|
@sent_an_int = false
|
18
|
-
@
|
19
|
-
@be_verbose = ARGV.include?("-v") || ARGV.include?("--verbose")
|
15
|
+
@verbose = ARGV.include?("-v") || ARGV.include?("--verbose")
|
20
16
|
@possible_map_locations = ["#{@working_directory}/.treasure_map.rb", "#{@working_directory}/treasure_map.rb", "#{@working_directory}/config/treasure_map.rb"]
|
21
17
|
end
|
22
|
-
|
23
|
-
def
|
18
|
+
|
19
|
+
def run
|
20
|
+
read_all_maps
|
21
|
+
set_all_examples if all_examples.empty?
|
22
|
+
prepare
|
23
|
+
start
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.run
|
24
27
|
beholder = new
|
25
|
-
beholder.
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
beholder.run
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def map_for(map_name)
|
33
|
+
@treasure_maps[map_name] ||= []
|
34
|
+
@current_map = @treasure_maps[map_name]
|
35
|
+
yield self if block_given?
|
36
|
+
ensure
|
37
|
+
@current_map = nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_mapping(pattern, &blk)
|
41
|
+
@current_map << [pattern, blk]
|
42
|
+
end
|
43
|
+
|
44
|
+
def watch(*paths)
|
45
|
+
self.paths_to_watch.concat(paths)
|
46
|
+
self.paths_to_watch.uniq!
|
47
|
+
self.paths_to_watch.sort!
|
48
|
+
end
|
49
|
+
|
50
|
+
alias :keep_a_watchful_eye_for :watch
|
51
|
+
alias :prepare_spell_for :add_mapping
|
52
|
+
|
53
|
+
def shutdown
|
54
|
+
watcher.shutdown
|
55
|
+
exit
|
56
|
+
end
|
57
|
+
|
58
|
+
def on_change(paths)
|
59
|
+
say "#{paths} changed" unless paths.nil? || paths.empty?
|
60
|
+
treasure_maps_changed = paths.select { |p| possible_map_locations.include?(p) }
|
61
|
+
treasure_maps_changed.each {|map_path| read_map_at(map_path) }
|
62
|
+
matches = paths.map { |path| find_matches(path) }.uniq.compact
|
63
|
+
run_tests matches
|
64
|
+
end
|
65
|
+
|
66
|
+
def examples_matching(name, suffix = "example")
|
67
|
+
regex = %r%.*#{name}_#{suffix}\.rb$%
|
68
|
+
all_examples.find_all { |ex| ex =~ regex }
|
69
|
+
end
|
70
|
+
|
71
|
+
def build_cmd(paths)
|
72
|
+
classes = paths.map { |p| p.gsub(".rb", "") }.join(" ")
|
73
|
+
puts "\nRunning #{paths.join(', ').inspect}"
|
74
|
+
|
75
|
+
execute = %[-e "%w[#{classes}].each { |f| require f }"]
|
76
|
+
# Pickup command from treasure map here, probably
|
77
|
+
cmd = "ruby #{execute}"
|
78
|
+
say cmd
|
79
|
+
cmd
|
29
80
|
end
|
30
81
|
|
31
82
|
def read_all_maps
|
32
83
|
read_default_map
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
84
|
+
possible_map_locations.each { |path| read_map_at(path) }
|
85
|
+
end
|
86
|
+
|
87
|
+
def read_map_at(path)
|
88
|
+
return unless File.exist?(path)
|
89
|
+
say "Found a map at #{path}"
|
90
|
+
begin
|
91
|
+
instance_eval(File.readlines(path).join("\n"))
|
92
|
+
rescue Object => e
|
93
|
+
puts "Exception caught trying to load map at #{path}"
|
94
|
+
puts e
|
40
95
|
end
|
41
96
|
end
|
42
97
|
|
43
|
-
|
98
|
+
protected
|
99
|
+
|
100
|
+
def prepare
|
44
101
|
trap 'INT' do
|
45
102
|
if @sent_an_int then
|
46
103
|
puts " A second INT? Ok, I get the message. Shutting down now."
|
47
|
-
|
104
|
+
shutdown
|
48
105
|
else
|
49
106
|
puts " Did you just send me an INT? Ugh. I'll quit for real if you do it again."
|
50
107
|
@sent_an_int = true
|
51
108
|
Kernel.sleep 1.5
|
52
|
-
|
109
|
+
run_tests all_examples
|
53
110
|
end
|
54
111
|
end
|
55
112
|
end
|
56
113
|
|
57
|
-
def
|
58
|
-
|
59
|
-
@
|
60
|
-
|
61
|
-
puts "\n\nWaiting
|
114
|
+
def start
|
115
|
+
startup_msg
|
116
|
+
@watcher = FSEvents::Stream.watch(paths_to_watch) do |event|
|
117
|
+
on_change(event.modified_files)
|
118
|
+
puts "\n\nWaiting for changes since #{Time.now}"
|
62
119
|
end
|
63
|
-
@
|
64
|
-
end
|
120
|
+
@watcher.run
|
121
|
+
end
|
122
|
+
|
123
|
+
def startup_msg
|
124
|
+
puts %[Beholder has loaded - CTRL-C once to reset, twice to quit.]
|
125
|
+
puts %[Watching the following paths: #{paths_to_watch.join(", ")}]
|
126
|
+
end
|
65
127
|
|
66
128
|
def read_default_map
|
67
|
-
map_for(:
|
129
|
+
map_for(:default) do |m|
|
68
130
|
|
69
|
-
|
131
|
+
m.watch 'lib', 'examples'
|
70
132
|
|
71
|
-
|
72
|
-
["examples/#{
|
133
|
+
m.add_mapping %r%examples/(.*)_example\.rb% do |match|
|
134
|
+
["examples/#{match[1]}_example.rb"]
|
73
135
|
end
|
74
136
|
|
75
|
-
|
137
|
+
m.add_mapping %r%examples/example_helper\.rb% do |match|
|
76
138
|
Dir["examples/**/*_example.rb"]
|
77
139
|
end
|
78
140
|
|
79
|
-
|
80
|
-
[
|
141
|
+
m.add_mapping %r%lib/(.*)\.rb% do |match|
|
142
|
+
examples_matching match[1]
|
81
143
|
end
|
82
144
|
|
83
145
|
end
|
84
146
|
end
|
85
|
-
|
86
|
-
def
|
87
|
-
@treasure_maps[map_name] ||= []
|
88
|
-
@current_map = @treasure_maps[map_name]
|
89
|
-
yield self if block_given?
|
90
|
-
ensure
|
91
|
-
@current_map = nil
|
92
|
-
end
|
93
|
-
|
94
|
-
def prepare_spell_for(arcane_enemy, &spell)
|
95
|
-
@current_map << [arcane_enemy, spell]
|
96
|
-
end
|
97
|
-
alias :add_mapping :prepare_spell_for
|
98
|
-
|
99
|
-
def cast_feeble_mind
|
147
|
+
|
148
|
+
def clear_maps
|
100
149
|
@treasure_maps = {}
|
101
150
|
end
|
102
151
|
|
@@ -114,57 +163,41 @@ class Beholder
|
|
114
163
|
end
|
115
164
|
end
|
116
165
|
|
117
|
-
def keep_a_watchful_eye_for(*paths)
|
118
|
-
@paths_to_watch.concat(paths)
|
119
|
-
end
|
120
|
-
|
121
166
|
def blink
|
122
167
|
@sent_an_int = false
|
123
168
|
end
|
124
169
|
|
125
|
-
def
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
treasure_maps.each do |name, treasure_locations|
|
132
|
-
treasure_locations.each do |stolen_by_enemy, spell|
|
133
|
-
if spell_components = treasure.match(stolen_by_enemy)
|
134
|
-
say "Found the stolen treasure using the #{name} map "
|
135
|
-
return spell.cast!(spell_components)
|
170
|
+
def find_matches(path)
|
171
|
+
treasure_maps.each do |name, map|
|
172
|
+
map.each do |pattern, blk|
|
173
|
+
if match = path.match(pattern)
|
174
|
+
say "Found the match for #{path} using the #{name} map "
|
175
|
+
return blk.call(match)
|
136
176
|
end
|
137
177
|
end
|
138
178
|
end
|
139
179
|
|
140
|
-
puts "Unknown file: #{
|
180
|
+
puts "Unknown file: #{path}"
|
141
181
|
return []
|
142
182
|
end
|
143
183
|
|
144
|
-
def
|
145
|
-
|
184
|
+
def run_tests(paths)
|
185
|
+
paths.flatten!
|
146
186
|
|
147
|
-
|
148
|
-
found_treasure = File.exist?(
|
149
|
-
puts "#{
|
187
|
+
paths.reject! do |path|
|
188
|
+
found_treasure = File.exist?(path)
|
189
|
+
puts "#{path} does not exist." unless found_treasure
|
150
190
|
end
|
151
191
|
|
152
|
-
return if
|
153
|
-
|
154
|
-
puts "\nRunning #{coordinates.join(', ').inspect}"
|
155
|
-
system "ruby #{coordinates.join(' ')}"
|
192
|
+
return if paths.empty?
|
193
|
+
system build_cmd(paths)
|
156
194
|
blink
|
157
195
|
end
|
158
|
-
|
159
|
-
def notice_thief_taking(treasure)
|
160
|
-
say "#{treasure} changed" unless treasure.empty?
|
161
|
-
coordinates = treasure.map { |t| identify_stolen_treasure(t) }.uniq.compact
|
162
|
-
reclaim_stolen_treasure_at coordinates
|
163
|
-
end
|
164
|
-
|
196
|
+
|
165
197
|
private
|
166
|
-
|
167
|
-
|
198
|
+
|
199
|
+
def say(msg)
|
200
|
+
puts msg if verbose
|
168
201
|
end
|
169
202
|
|
170
|
-
end
|
203
|
+
end
|
metadata
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spicycode-beholder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Chad Humphries
|
8
|
-
autorequire:
|
7
|
+
- Chad Humphries, Rob Sanheim
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-05 00:00:00 -07:00
|
13
13
|
default_executable: beholder
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: fsevents
|
17
|
+
type: :runtime
|
17
18
|
version_requirement:
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
19
20
|
requirements:
|
@@ -21,8 +22,8 @@ dependencies:
|
|
21
22
|
- !ruby/object:Gem::Version
|
22
23
|
version: "0"
|
23
24
|
version:
|
24
|
-
description:
|
25
|
-
email: chad@spicycode.com
|
25
|
+
description: beholder
|
26
|
+
email: chad@spicycode.com, rsanheim@gmail.com
|
26
27
|
executables:
|
27
28
|
- beholder
|
28
29
|
extensions: []
|
@@ -42,10 +43,11 @@ files:
|
|
42
43
|
- examples/lib/beholder_example.rb
|
43
44
|
- bin/beholder
|
44
45
|
has_rdoc: true
|
45
|
-
homepage: http://github.com/
|
46
|
+
homepage: http://github.com/rsanheim/beholder
|
46
47
|
post_install_message:
|
47
|
-
rdoc_options:
|
48
|
-
|
48
|
+
rdoc_options:
|
49
|
+
- --inline-source
|
50
|
+
- --charset=UTF-8
|
49
51
|
require_paths:
|
50
52
|
- lib
|
51
53
|
required_ruby_version: !ruby/object:Gem::Requirement
|