autorun 0.1.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.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +6 -0
- data/autorun.gemspec +24 -0
- data/lib/autorun.rb +31 -0
- data/lib/autorun/version.rb +3 -0
- data/spec/autorun_spec.rb +37 -0
- data/spec/spec_helper.rb +3 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YTM3YjY2YjlhMDlhZDlhY2FhZDY3NTg3NmI1MzM2YzZkZDM3MzhhMw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
N2ZkMTVlNGU2OWNhY2M2MzdjZDAzNWJlYjQ1NTdiNmMzYWEzOGFjZA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MmY4MzVlZGY4ZjY0YTNkMDQyNGY4NzQ4YTAwOTY0ZjBmNWJhYmJhYjEyODM1
|
10
|
+
MTgxZmU3NjZlMmNkOTI4YzQ4MDJkMTJjNjg0N2FjMGQ1YjFkNDA1MDVmODQz
|
11
|
+
YjdmNzc5MjAyMzc5NjMxOTRjZDFiM2M5NjA3NzI3YjRkNTYyOTQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MjA1MjYxNWEwNWJlYjNmMmUwMzI5NWVlMjA1MDQ0YTJmMDBkYjAxZTE5ZjZi
|
14
|
+
Mjg5ZGExZmI5YzZlYWYxZjVlYzkzNDFhMWZkY2IwMWU0ZmI0MGUyZTAzNGQy
|
15
|
+
OTI3MDk1ZjlmYmEwMzFjMjlhNDY0NjBkNmVkN2EzNzgyNjdhOWI=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Shintaro Torii
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Autorun
|
2
|
+
|
3
|
+
Autorun is a simple scripting helper module. It allows you write a simple executable script per class easily.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Autorun is a module which invokes 'run' method automatically.
|
8
|
+
|
9
|
+
* Implement an executable class and include Autorun.
|
10
|
+
|
11
|
+
```
|
12
|
+
#!/usr/bin/env ruby
|
13
|
+
require 'autorun'
|
14
|
+
|
15
|
+
class DailyBatch
|
16
|
+
include Autorun
|
17
|
+
|
18
|
+
def run
|
19
|
+
# ...
|
20
|
+
end
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
* Then execute it.
|
25
|
+
|
26
|
+
```
|
27
|
+
$ ruby daily_batch.rb
|
28
|
+
```
|
29
|
+
|
30
|
+
* When you need to use other method name instead of 'run', use simply alias_method.
|
31
|
+
|
32
|
+
```
|
33
|
+
class WorkerJob
|
34
|
+
include Autorun
|
35
|
+
|
36
|
+
def perform
|
37
|
+
# ...
|
38
|
+
end
|
39
|
+
|
40
|
+
alias_method :run, :perform
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
* Autorun does not provide other features such as option parser, please use appropriate gem like 'thor' or 'slop'.
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it ( http://github.com/twodollarz/autorun/fork )
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/autorun.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'autorun/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "autorun"
|
8
|
+
spec.version = Autorun::VERSION
|
9
|
+
spec.authors = ["Shintaro Torii"]
|
10
|
+
spec.email = ["shintaro.torii@gmail.com"]
|
11
|
+
spec.description = %q{A simple scripting helper module}
|
12
|
+
spec.summary = %q{Autorun allows you write a simple executable script per class easily}
|
13
|
+
spec.homepage = "https://github.com/twodollarz/autorun"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
data/lib/autorun.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'autorun/version'
|
2
|
+
|
3
|
+
module Autorun
|
4
|
+
@run_classes = []
|
5
|
+
@is_at_exit = false
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
@run_classes << base
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.run
|
12
|
+
@run_classes.each do |run_class|
|
13
|
+
run_class.new.run
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.is_at_exit_added?
|
18
|
+
@is_at_exit
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.is_at_exit_added=(bool)
|
22
|
+
@is_at_exit = bool
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
unless Autorun.is_at_exit_added?
|
27
|
+
at_exit do
|
28
|
+
Autorun.run if $!.nil?
|
29
|
+
end
|
30
|
+
Autorun.is_at_exit_added = true
|
31
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Autorun do
|
4
|
+
let(:klass) do
|
5
|
+
Class.new do
|
6
|
+
include Autorun
|
7
|
+
def run
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe :included do
|
13
|
+
it 'can be included by a class' do
|
14
|
+
klass.ancestors.should include Autorun
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe :is_at_exit_added? do
|
19
|
+
it 'should be true' do
|
20
|
+
Autorun.is_at_exit_added?.should be_true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe :is_at_exit_added= do
|
25
|
+
before { Autorun.is_at_exit_added = false }
|
26
|
+
it 'should change the value' do
|
27
|
+
Autorun.is_at_exit_added?.should be_false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe :run do
|
32
|
+
it 'runs included class' do
|
33
|
+
klass.any_instance.should_receive(:run)
|
34
|
+
Autorun.run
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: autorun
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shintaro Torii
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A simple scripting helper module
|
56
|
+
email:
|
57
|
+
- shintaro.torii@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- autorun.gemspec
|
68
|
+
- lib/autorun.rb
|
69
|
+
- lib/autorun/version.rb
|
70
|
+
- spec/autorun_spec.rb
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
homepage: https://github.com/twodollarz/autorun
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.1.11
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Autorun allows you write a simple executable script per class easily
|
96
|
+
test_files:
|
97
|
+
- spec/autorun_spec.rb
|
98
|
+
- spec/spec_helper.rb
|