cigarette 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ * Copyright (c) 2012, Thibaut Deloffre
2
+ * All rights reserved.
3
+ * Redistribution and use in source and binary forms, with or without
4
+ * modification, are permitted provided that the following conditions are met:
5
+ *
6
+ * * Redistributions of source code must retain the above copyright
7
+ * notice, this list of conditions and the following disclaimer.
8
+ * * Redistributions in binary form must reproduce the above copyright
9
+ * notice, this list of conditions and the following disclaimer in the
10
+ * documentation and/or other materials provided with the distribution.
11
+ * * Neither the name of RocknRoot nor the names of its contributors may
12
+ * be used to endorse or promote products derived from this software
13
+ * without specific prior written permission.
14
+ *
15
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
16
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
19
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cigarette'
4
+
5
+ Cigarette.new
@@ -0,0 +1,57 @@
1
+ require 'yaml'
2
+ require 'cigarette/numeric.rb'
3
+
4
+ class Cigarette
5
+
6
+ VERSION = "1.0"
7
+ # Hope.
8
+ CANCER_DO_NOT_APPEAR = 42
9
+
10
+ def initialize
11
+ begin
12
+ cnf = YAML::load(File.open("#{Dir.pwd}/.cigarette"))
13
+ @time = (cnf[:each] || cnf['each']).to_i
14
+ @next_check = Time.now.to_i + @time
15
+ @command = cnf[:command] || cnf['command']
16
+ rescue TypeError
17
+ abort "Didn't you make a mistake in .cigarette file ?"
18
+ rescue ArgumentError
19
+ abort "Did you configure attribute like this: 'attribute: <value>'"
20
+ rescue Exception => e
21
+ abort "Problem during .cigarette loading: #{e.message}"
22
+ end
23
+ puts "Cigarette launched - version #{VERSION}."
24
+ lighter_please!
25
+ end
26
+
27
+ private
28
+
29
+ def lighter_please!
30
+ while CANCER_DO_NOT_APPEAR
31
+ sleep 0.1
32
+ if time_to_light_up?
33
+ output = `#{@command} 2>&1`
34
+ status = $?.success? unless defined? status
35
+ current_status = $?.success?
36
+ banner = ($?.success? ? "SUCCESS" : "ERROR(S)")
37
+ puts "#{banner} - #{@current_time.strftime("at: %T")}"
38
+ if status != current_status
39
+ puts output
40
+ end
41
+ status = current_status
42
+ end
43
+ end
44
+ end
45
+
46
+ def time_to_light_up?
47
+ @current_time = Time.now
48
+ if @current_time.to_i >= @next_check
49
+ @next_check = Time.now.to_i + @time
50
+ true
51
+ else
52
+ false
53
+ end
54
+ end
55
+
56
+ end
57
+
@@ -0,0 +1,19 @@
1
+ class Numeric
2
+
3
+ def second
4
+ self
5
+ end
6
+
7
+ def minute
8
+ self * 60
9
+ end
10
+
11
+ def hour
12
+ self * 3600
13
+ end
14
+
15
+ alias :seconds :second
16
+ alias :minutes :minute
17
+ alias :hours :hour
18
+
19
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cigarette
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ version: "1.0"
10
+ platform: ruby
11
+ authors:
12
+ - Thibaut Deloffre
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-12-20 00:00:00 Z
18
+ dependencies: []
19
+
20
+ description: Tiny test tool
21
+ email: tib@rocknroot.org
22
+ executables:
23
+ - cigarette
24
+ extensions: []
25
+
26
+ extra_rdoc_files:
27
+ - LICENSE.txt
28
+ files:
29
+ - lib/cigarette.rb
30
+ - lib/cigarette/numeric.rb
31
+ - LICENSE.txt
32
+ - bin/cigarette
33
+ homepage: https://github.com/TibshoOT/cigarette
34
+ licenses:
35
+ - BSD
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.24
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Tiny test tool
66
+ test_files: []
67
+