rat 0.2.0

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ryan Koopmans
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.rdoc ADDED
@@ -0,0 +1,29 @@
1
+ = rat
2
+
3
+ Ruby interface to Unix "at" command.
4
+
5
+ == Installation
6
+
7
+ $ gem sources -a http://gems.github.com # you only need to run this once
8
+ $ sudo gem install koops-rat
9
+
10
+ == Usage
11
+
12
+ $ require 'rat'
13
+ $ job = Rat.add('touch at-at', Time.now + 30)
14
+ $ # => <integer id>
15
+ $ # Thirty seconds later, the touch command runs.
16
+ $ Rat.list
17
+ $ # => [{:job => <integer id>, :time => Thu Oct 08 09:08:51 -0700 2009}, ...]
18
+ $ Rat.delete(job) # if you change your mind about running the command.
19
+
20
+ == Notes
21
+ "At" stores your environment, including your working directory, so you don't need full pathnames to executables, etc. like you do in cron (though it doesn't hurt).
22
+
23
+ == MacOS X
24
+
25
+ Note that, by default, "at" is disabled on MacOS X. See "man atrun" for the command to enable it.
26
+
27
+ == Copyright
28
+
29
+ Copyright (c) 2009 Ryan Koopmans. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rat"
8
+ gem.summary = %Q{Ruby interface to Unix "at" command.}
9
+ gem.description = %Q{Ruby interface to Unix "at" command. (Not compatible with Windows\' "at".)}
10
+ gem.email = "koops@editcx.com"
11
+ gem.homepage = "http://github.com/koops/rat"
12
+ gem.authors = ["Ryan Koopmans"]
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+ task :test => :check_dependencies
40
+
41
+ task :default => :test
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ if File.exist?('VERSION')
46
+ version = File.read('VERSION')
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "rat #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
data/lib/rat.rb ADDED
@@ -0,0 +1,44 @@
1
+ class Date # :nodoc:
2
+ def to_system_time
3
+ to_time(new_offset, :local)
4
+ end
5
+
6
+ private
7
+ def to_time(dest, method)
8
+ Time.send(method, dest.year, dest.month, dest.day, dest.hour, dest.min, dest.sec)
9
+ end
10
+ end
11
+
12
+ module Rat
13
+ # Schedule a new at job. Time is local time. Pass :no_mail => true in options to supress email for jobs with output.
14
+ def self.add(command, time, opts = {})
15
+ cmd = command.dup
16
+ cmd << ' 2>&1 > /dev/null' if opts[:no_mail]
17
+ output = `echo "#{cmd}" | at -t #{time.strftime('%y%m%d%H%M.%S')} 2>&1`
18
+ raise RuntimeError, "Rat couldn't schedule job." unless $?.exitstatus == 0
19
+ (output[/job (\d+)/i, 1] || -1).to_i
20
+ end
21
+
22
+ # Pass an integer id returned from add or list.
23
+ def self.remove(job)
24
+ `at -r #{job}`
25
+ $?.exitstatus == 0
26
+ end
27
+
28
+ # Dumps the entire job, with environment. Handy for debugging failed jobs.
29
+ def self.show(job)
30
+ `at -c #{job}`
31
+ end
32
+
33
+ # Gives all the pending at jobs for the current user.
34
+ # [{:job => int, :time => time}, ...]
35
+ def self.list
36
+ output = `at -l`
37
+ raise RuntimeError, "Rat couldn't list jobs." unless $?.exitstatus == 0
38
+
39
+ output.map do |l|
40
+ l =~ /(\d+)\t(.*)/
41
+ {:job => ($1 || -1).to_i, :time => DateTime.parse($2).to_system_time}
42
+ end
43
+ end
44
+ end
data/rat.gemspec ADDED
@@ -0,0 +1,50 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rat}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ryan Koopmans"]
12
+ s.date = %q{2009-10-08}
13
+ s.description = %q{Ruby interface to Unix "at" command. (Not compatible with Windows' "at".)}
14
+ s.email = %q{koops@editcx.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/rat.rb",
27
+ "rat.gemspec",
28
+ "test/rat_test.rb",
29
+ "test/test_helper.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/koops/rat}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.5}
35
+ s.summary = %q{Ruby interface to Unix "at" command.}
36
+ s.test_files = [
37
+ "test/rat_test.rb",
38
+ "test/test_helper.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ else
47
+ end
48
+ else
49
+ end
50
+ end
data/test/rat_test.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'test/test_helper'
2
+
3
+ class RatTest < Test::Unit::TestCase
4
+ def test_lifecycle
5
+ job = 0
6
+ assert_difference('Rat.list.size') do
7
+ job = Rat.add('echo ratty', Time.now + 100, :no_mail => true)
8
+ end
9
+
10
+ assert job > 0
11
+ assert /echo ratty/, Rat.show(job)
12
+ assert_equal job, Rat.list.last[:job]
13
+ assert Rat.list.last[:time].is_a?(Time)
14
+
15
+ assert_difference('Rat.list.size', -1) do
16
+ Rat.remove(job)
17
+ end
18
+ end
19
+
20
+ def test_inner_quotes
21
+ assert_nothing_raised{ Rat.add('echo "ratty"', Time.now + 100, :no_mail => true) }
22
+ assert_nothing_raised{ Rat.add("echo 'ratty'", Time.now + 100, :no_mail => true) }
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'rat'
7
+
8
+ class Test::Unit::TestCase
9
+ def assert_difference(expression, difference = 1, message = nil, &block)
10
+ b = block.send(:binding)
11
+ before = eval(expression, b)
12
+
13
+ yield
14
+
15
+ error = "#{expression.inspect} didn't change by #{difference}"
16
+ error = "#{message}.\n#{error}" if message
17
+ assert_equal(before + difference, eval(expression, b), error)
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Koopmans
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-08 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Ruby interface to Unix "at" command. (Not compatible with Windows' "at".)
17
+ email: koops@editcx.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/rat.rb
33
+ - rat.gemspec
34
+ - test/rat_test.rb
35
+ - test/test_helper.rb
36
+ has_rdoc: true
37
+ homepage: http://github.com/koops/rat
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --charset=UTF-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.5
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Ruby interface to Unix "at" command.
64
+ test_files:
65
+ - test/rat_test.rb
66
+ - test/test_helper.rb