touch_wrap 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in touch-wrap.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,21 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^spec/.+_spec\.rb$})
11
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
12
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
13
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
14
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
15
+ watch('spec/spec_helper.rb') { "spec" }
16
+ watch('config/routes.rb') { "spec/routing" }
17
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
18
+ # Capybara request specs
19
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
20
+ end
21
+
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Aleksey Gureiev and Recess Mobile Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ Touch Wrap
2
+ ==========
3
+
4
+ It's a tiny library to let you wrap the code with two file touches -- before execution of
5
+ a block and after the successful finish. This is useful when you are monitoring code blocks
6
+ with an external service, like Monit.
7
+
8
+ Usage
9
+ -----
10
+
11
+ # Touch /tmp/task before the run, and /tmp/task.success upon completion
12
+ TouchWrap('/tmp/task') do
13
+ # your code
14
+ end
15
+
16
+ # Touch /tmp/task before, and /tmp/task.done after
17
+ TouchWrap('/tmp/task', '/tmp/task.done') do
18
+ # your code
19
+ end
20
+
21
+ License
22
+ -------
23
+
24
+ Copyright (c) 2011 Aleksey Gureiev and Recess Mobile Inc.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module TouchWrap
2
+ VERSION = "0.0.1"
3
+ end
data/lib/touch_wrap.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "touch_wrap/version"
2
+
3
+ def TouchWrap(main_file, success_file = "#{main_file}.success")
4
+ FileUtils.touch main_file
5
+ yield
6
+ FileUtils.touch success_file
7
+ end
@@ -0,0 +1,58 @@
1
+ require 'touch_wrap'
2
+ describe TouchWrap do
3
+ let(:file) { "/tmp/touch_wrap" }
4
+ let(:success_file) { "#{file}.success" }
5
+
6
+ before { FileUtils.rm_f [ file, "#{file}.success" ] }
7
+
8
+ context "successful execution" do
9
+ before do
10
+ TouchWrap(file) do
11
+ @code = :executed
12
+ end
13
+ end
14
+
15
+ specify { @code.should be :executed }
16
+
17
+ it "should touch the main file" do
18
+ File.exists?(file).should be_true
19
+ end
20
+
21
+ it "should touch the .success file" do
22
+ File.exists?(success_file).should be_true
23
+ end
24
+ end
25
+
26
+ context "failed execution" do
27
+ before do
28
+ begin
29
+ TouchWrap(file) do
30
+ # failure
31
+ raise "Some error"
32
+ end
33
+ rescue
34
+ # Ignore the error
35
+ end
36
+ end
37
+
38
+ it "should touch the main file" do
39
+ File.exists?(file).should be_true
40
+ end
41
+
42
+ it "shouldn't touch the .success file" do
43
+ File.exists?(success_file).should be_false
44
+ end
45
+ end
46
+
47
+ context "bad file name" do
48
+ before do
49
+ lambda {
50
+ TouchWrap('/bad/filename') do
51
+ @code = :executed
52
+ end
53
+ }.should raise_error
54
+ end
55
+ specify { @code.should_not be :executed }
56
+ end
57
+
58
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "touch_wrap/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "touch_wrap"
7
+ s.version = TouchWrap::VERSION
8
+ s.authors = ["Aleksey Gureiev"]
9
+ s.email = ["spyromus@noizeramp.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Wraps the code with two file touches.}
12
+ s.description = %q{Use the gem to monitor the execution and successful completion of the code block.}
13
+
14
+ s.rubyforge_project = "touch_wrap"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "rspec"
22
+ s.add_development_dependency "guard"
23
+ s.add_development_dependency "guard-rspec"
24
+
25
+ # s.add_runtime_dependency "rest-client"
26
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: touch_wrap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aleksey Gureiev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70262583099660 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70262583099660
25
+ - !ruby/object:Gem::Dependency
26
+ name: guard
27
+ requirement: &70262583095920 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70262583095920
36
+ - !ruby/object:Gem::Dependency
37
+ name: guard-rspec
38
+ requirement: &70262583109340 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70262583109340
47
+ description: Use the gem to monitor the execution and successful completion of the
48
+ code block.
49
+ email:
50
+ - spyromus@noizeramp.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - Guardfile
58
+ - MIT-LICENSE
59
+ - README.md
60
+ - Rakefile
61
+ - lib/touch_wrap.rb
62
+ - lib/touch_wrap/version.rb
63
+ - spec/touch_wrap_spec.rb
64
+ - touch_wrap.gemspec
65
+ homepage: ''
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project: touch_wrap
85
+ rubygems_version: 1.8.10
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Wraps the code with two file touches.
89
+ test_files:
90
+ - spec/touch_wrap_spec.rb