kuzushi 0.0.23 → 0.0.24

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.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/kuzushi.rb +20 -6
  3. data/spec/kuzushi_spec.rb +25 -0
  4. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.23
1
+ 0.0.24
@@ -9,6 +9,8 @@ require 'erb'
9
9
 
10
10
  ## firewall until ready
11
11
  ## ruby 1.9 compatibility
12
+ ## nested configs
13
+ ## user configs
12
14
 
13
15
  class Kuzushi
14
16
  attr_accessor :config, :config_names
@@ -243,6 +245,17 @@ class Kuzushi
243
245
  end
244
246
  end
245
247
 
248
+
249
+ def script(scripts)
250
+ to_array(scripts).each do |s|
251
+ if s =~ /^#!/
252
+ inline_script(s)
253
+ else
254
+ external_script(s)
255
+ end
256
+ end
257
+ end
258
+
246
259
  def inline_script(script)
247
260
  tmpfile(script) do |tmp|
248
261
  task "run inline script" do
@@ -251,10 +264,7 @@ class Kuzushi
251
264
  end
252
265
  end
253
266
 
254
- def script(script)
255
- return if script.nil?
256
- return inline_script(script) if script =~ /^#!/
257
-
267
+ def external_script(script)
258
268
  fetch("/scripts/#{script}") do |file|
259
269
  task "run script #{script}" do
260
270
  shell "#{file}"
@@ -271,7 +281,7 @@ class Kuzushi
271
281
 
272
282
  def file(f, &blk)
273
283
  ## no magic here - move along
274
- fetch("/templates/#{f.template}", lambda { |data| erb data }, &blk) if f.template
284
+ fetch("/templates/#{f.template}", lambda { |data| erb data }, &blk) if f.template
275
285
  fetch("/files/#{f.source || File.basename(f.file)}", &blk) unless f.template
276
286
  end
277
287
 
@@ -301,7 +311,11 @@ class Kuzushi
301
311
  end
302
312
 
303
313
  def get_array(key)
304
- [ get(key) || [] ].flatten
314
+ to_array( get(key) )
315
+ end
316
+
317
+ def to_array(value)
318
+ [ value || [] ].flatten
305
319
  end
306
320
 
307
321
  def wait_for_volume(vol)
@@ -77,5 +77,30 @@ describe Kuzushi do
77
77
  @kuzushi.expects(:shell).with("crontab -u root #{tmpfile}")
78
78
  should.not.raise { @kuzushi.start }
79
79
  end
80
+
81
+ it "will run external scripts" do
82
+ @kuzushi.stubs(:config).returns( {
83
+ "before" => "script.sh"
84
+ })
85
+ @kuzushi.expects(:external_script).with("script.sh")
86
+ should.not.raise { @kuzushi.start }
87
+ end
88
+
89
+ it "will run inline scripts" do
90
+ @kuzushi.stubs(:config).returns( {
91
+ "before" => "#!/bin/bash\n echo 'hello'\n"
92
+ })
93
+ @kuzushi.expects(:inline_script).with("#!/bin/bash\n echo 'hello'\n")
94
+ should.not.raise { @kuzushi.start }
95
+ end
96
+
97
+ it "will run sets of scripts" do
98
+ @kuzushi.stubs(:config).returns( {
99
+ "before" => [ "script.sh", "#!/bin/bash\n echo 'hello'\n" ]
100
+ })
101
+ @kuzushi.expects(:inline_script).with("#!/bin/bash\n echo 'hello'\n")
102
+ @kuzushi.expects(:external_script).with("script.sh")
103
+ should.not.raise { @kuzushi.start }
104
+ end
80
105
  end
81
106
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kuzushi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.23
4
+ version: 0.0.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Orion Henry