spicycode-beholder 0.5.3 → 0.5.4

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 CHANGED
@@ -59,4 +59,7 @@ map_for(:beholders_lair) do |wizard|
59
59
  # Dir["examples/foobar/*_example.rb"]
60
60
  # end
61
61
 
62
+ # You could set the list of all examples to be run after pressing ctrl-c once
63
+ # it defaults to any files in examples, spec, and test
64
+ wizard.all_examples = Dir['your/path/**/*_here.rb']
62
65
  end
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'date'
5
5
  require 'micronaut/rake_task'
6
6
 
7
7
  GEM = "beholder"
8
- GEM_VERSION = "0.5.3"
8
+ GEM_VERSION = "0.5.4"
9
9
  AUTHOR = "Chad Humphries"
10
10
  EMAIL = "chad@spicycode.com"
11
11
  HOMEPAGE = "http://github.com/spicycode/beholder"
@@ -5,14 +5,16 @@ describe Beholder do
5
5
  describe "when casting it's gaze" do
6
6
 
7
7
  it "should begat a new beholder" do
8
- beholder = stub(Beholder.new) { prepare_for_interlopers; open_your_eye }
8
+ beholder = stub(Beholder.new) { prepare_for_interlopers; open_your_eye; spawn_dragon }
9
9
  mock(Beholder).new { beholder }
10
+
10
11
  Beholder.cast_thy_gaze
11
12
  end
12
13
 
13
14
  it "should prepare the child for interlopers" do
14
15
  beholder = Beholder.new
15
16
  stub(beholder).open_your_eye
17
+ stub(beholder).spawn_dragon
16
18
  mock(beholder).prepare_for_interlopers
17
19
  stub(Beholder).new { beholder }
18
20
 
@@ -22,6 +24,7 @@ describe Beholder do
22
24
  it "should open the child's eyes" do
23
25
  beholder = Beholder.new
24
26
  mock(beholder).open_your_eye
27
+ stub(beholder).spawn_dragon
25
28
  stub(beholder).prepare_for_interlopers
26
29
  stub(Beholder).new { beholder }
27
30
 
@@ -32,12 +35,6 @@ describe Beholder do
32
35
 
33
36
  describe "when it notices a thief taking treasure" do
34
37
 
35
- it "should howl about the theft" do
36
- beholder = Beholder.new
37
- mock(beholder).say "#{[]} changed"
38
- beholder.notice_thief_taking []
39
- end
40
-
41
38
  it "should identify what was stolen" do
42
39
  treasures = ['pot_o_gold']
43
40
  beholder = Beholder.new
data/lib/beholder.rb CHANGED
@@ -8,111 +8,135 @@ end
8
8
 
9
9
  class Beholder
10
10
 
11
- attr_reader :paths_to_watch, :sent_an_int, :mappings, :working_directory, :be_verbose, :the_eye, :treasure_maps, :corpses
11
+ attr_reader :paths_to_watch, :sent_an_int, :mappings, :working_directory, :be_verbose
12
+ attr_reader :the_eye, :treasure_maps, :possible_map_locations, :all_examples
12
13
 
13
14
  def initialize
14
- @paths_to_watch = []
15
+ @paths_to_watch, @all_examples = [], []
16
+ @mappings, @treasure_maps = {}, {}
15
17
  @sent_an_int = false
16
- @mappings = {}
17
18
  @working_directory = Dir.pwd
18
19
  @be_verbose = ARGV.include?("-v") || ARGV.include?("--verbose")
19
- @treasure_maps = {}
20
- @corpses = ["#{@working_directory}/.treasure_map.rb", "#{@working_directory}/treasure_map.rb", "#{@working_directory}/config/treasure_map.rb"]
20
+ @possible_map_locations = ["#{@working_directory}/.treasure_map.rb", "#{@working_directory}/treasure_map.rb", "#{@working_directory}/config/treasure_map.rb"]
21
21
  end
22
-
22
+
23
23
  def self.cast_thy_gaze
24
24
  beholder = new
25
- beholder.read_all_the_maps
25
+ beholder.read_all_maps
26
+ beholder.set_all_examples if beholder.all_examples.empty?
26
27
  beholder.prepare_for_interlopers
27
28
  beholder.open_your_eye
28
29
  end
29
-
30
+
31
+ def read_all_maps
32
+ read_default_map
33
+
34
+ possible_map_locations.each do |map_location|
35
+ if File.exist?(map_location)
36
+ say "Found a treasure map at #{map_location}"
37
+ instance_eval(File.readlines(map_location).join("\n"))
38
+ return
39
+ end
40
+ end
41
+ end
42
+
43
+ def prepare_for_interlopers
44
+ trap 'INT' do
45
+ if @sent_an_int then
46
+ puts " A second INT? Ok, I get the message. Shutting down now."
47
+ close_your_eye
48
+ else
49
+ puts " Did you just send me an INT? Ugh. I'll quit for real if you do it again."
50
+ @sent_an_int = true
51
+ Kernel.sleep 1.5
52
+ reclaim_stolen_treasure_at all_examples
53
+ end
54
+ end
55
+ end
56
+
30
57
  def open_your_eye
31
58
  say("Watching the following locations:\n #{paths_to_watch.join(", ")}")
32
59
  @the_eye = FSEvents::Stream.watch(paths_to_watch) do |treasure_chest|
33
60
  notice_thief_taking(treasure_chest.modified_files)
34
- blink
35
61
  puts "\n\nWaiting to hear from the disk since #{Time.now}"
36
62
  end
37
63
  @the_eye.run
38
64
  end
39
65
 
66
+ def read_default_map
67
+ map_for(:default_dungeon) do |wizard|
68
+
69
+ wizard.keep_a_watchful_eye_for 'lib', 'examples'
70
+
71
+ wizard.prepare_spell_for %r%examples/(.*)_example\.rb% do |spell_component|
72
+ ["examples/#{spell_component[1]}_example.rb"]
73
+ end
74
+
75
+ wizard.prepare_spell_for %r%examples/example_helper\.rb% do |spell_component|
76
+ Dir["examples/**/*_example.rb"]
77
+ end
78
+
79
+ wizard.prepare_spell_for %r%lib/(.*)\.rb% do |spell_component|
80
+ ["examples/lib/#{spell_component[1]}_example.rb"]
81
+ end
82
+
83
+ end
84
+ end
85
+
40
86
  def map_for(map_name)
41
87
  @treasure_maps[map_name] ||= []
42
88
  @current_map = @treasure_maps[map_name]
43
89
  yield self if block_given?
90
+ ensure
44
91
  @current_map = nil
45
92
  end
46
-
93
+
47
94
  def prepare_spell_for(arcane_enemy, &spell)
48
95
  @current_map << [arcane_enemy, spell]
49
96
  end
50
97
  alias :add_mapping :prepare_spell_for
51
-
98
+
52
99
  def cast_feeble_mind
53
100
  @treasure_maps = {}
54
101
  end
55
102
 
56
- def keep_a_watchful_eye_for(*paths)
57
- @paths_to_watch.concat(paths)
58
- end
59
-
60
- def read_all_the_maps
61
- map_for(:default_dungeon) do |wizard|
62
-
63
- wizard.keep_a_watchful_eye_for 'lib', 'examples'
64
-
65
- wizard.prepare_spell_for %r%examples/(.*)_example\.rb% do |spell_component|
66
- ["examples/#{spell_component[1]}_example.rb"]
67
- end
68
-
69
- wizard.prepare_spell_for %r%examples/example_helper\.rb% do |spell_component|
70
- Dir["examples/**/*_example.rb"]
71
- end
72
-
73
- wizard.prepare_spell_for %r%lib/(.*)\.rb% do |spell_component|
74
- ["examples/lib/#{spell_component[1]}_example.rb"]
75
- end
76
-
77
-
103
+ def set_all_examples
104
+ if paths_to_watch.include?('examples')
105
+ @all_examples += Dir['examples/**/*_example.rb']
106
+ end
107
+
108
+ if paths_to_watch.include?('test')
109
+ @all_examples += Dir['test/**/*_test.rb']
78
110
  end
79
111
 
80
- loot_corpses
112
+ if paths_to_watch.include?('spec')
113
+ @all_examples += Dir['spec/**/*_spec.rb']
114
+ end
81
115
  end
82
-
83
- def loot_corpses
84
- corpses.each do |corpse|
85
- if File.exist?(corpse)
86
- say "Found a treasure map on #{corpse}"
87
- instance_eval(File.readlines(corpse).join("\n"))
88
- return
89
- end
90
- end
116
+
117
+ def keep_a_watchful_eye_for(*paths)
118
+ @paths_to_watch.concat(paths)
91
119
  end
92
-
120
+
93
121
  def blink
94
122
  @sent_an_int = false
95
123
  end
96
-
124
+
97
125
  def close_your_eye
98
126
  the_eye.shutdown
99
127
  exit
100
128
  end
101
-
129
+
102
130
  def identify_stolen_treasure(treasure)
103
131
  treasure_maps.each do |name, treasure_locations|
104
-
105
132
  treasure_locations.each do |stolen_by_enemy, spell|
106
-
107
133
  if spell_components = treasure.match(stolen_by_enemy)
108
134
  say "Found the stolen treasure using the #{name} map "
109
135
  return spell.cast!(spell_components)
110
136
  end
111
-
112
137
  end
113
-
114
138
  end
115
-
139
+
116
140
  puts "Unknown file: #{treasure}"
117
141
  return []
118
142
  end
@@ -121,15 +145,15 @@ class Beholder
121
145
  coordinates.flatten!
122
146
 
123
147
  coordinates.reject! do |coordinate|
124
- not_there = !File.exist?(coordinate)
125
- puts "Example #{coordinate} does not actually exist." if not_there
126
- not_there
148
+ found_treasure = File.exist?(coordinate)
149
+ puts "#{coordinate} does not exist." unless found_treasure
127
150
  end
128
-
151
+
129
152
  return if coordinates.empty?
130
-
153
+
131
154
  puts "\nRunning #{coordinates.join(', ').inspect}"
132
155
  system "ruby #{coordinates.join(' ')}"
156
+ blink
133
157
  end
134
158
 
135
159
  def notice_thief_taking(treasure)
@@ -137,23 +161,10 @@ class Beholder
137
161
  coordinates = treasure.map { |t| identify_stolen_treasure(t) }.uniq.compact
138
162
  reclaim_stolen_treasure_at coordinates
139
163
  end
140
-
141
- def prepare_for_interlopers
142
- trap 'INT' do
143
- if @sent_an_int then
144
- puts " A second INT? Ok, I get the message. Shutting down now."
145
- close_your_eye
146
- else
147
- puts " Did you just send me an INT? Ugh. I'll quit for real if you do it again."
148
- @sent_an_int = true
149
- Kernel.sleep 1.5
150
- end
151
- end
152
- end
153
-
164
+
154
165
  private
155
166
  def say(this_message_please)
156
167
  puts this_message_please if be_verbose
157
168
  end
158
-
169
+
159
170
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spicycode-beholder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Humphries
@@ -9,7 +9,7 @@ autorequire: beholder
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-16 00:00:00 -08:00
12
+ date: 2009-01-18 00:00:00 -08:00
13
13
  default_executable: beholder
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency