Shorty 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/README.md +45 -0
- data/Rakefile +3 -0
- data/Shorty.gemspec +31 -0
- data/lib/Shorty.rb +79 -0
- data/lib/Shorty/version.rb +3 -0
- data/spec/helper.rb +15 -0
- data/spec/main.rb +15 -0
- data/spec/tests/DSL.rb +14 -0
- data/spec/tests/Shorty.rb +67 -0
- data/spec/tests/bin.rb +13 -0
- metadata +138 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
Shorty
|
3
|
+
================
|
4
|
+
|
5
|
+
A Ruby gem.
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
|
10
|
+
gem install Shorty
|
11
|
+
|
12
|
+
Usage
|
13
|
+
------
|
14
|
+
|
15
|
+
require "Shorty"
|
16
|
+
|
17
|
+
include Shorty::DSL
|
18
|
+
|
19
|
+
add :ssh, My_SSH_Commands.new
|
20
|
+
|
21
|
+
before :ssh, :restart do
|
22
|
+
puts "restarting SSH"
|
23
|
+
end
|
24
|
+
|
25
|
+
after :ssh, :restart do
|
26
|
+
puts "SSH has been restarted"
|
27
|
+
end
|
28
|
+
|
29
|
+
run :ssh, :restart
|
30
|
+
|
31
|
+
|
32
|
+
Run Tests
|
33
|
+
---------
|
34
|
+
|
35
|
+
git clone git@github.com:da99/Shorty.git
|
36
|
+
cd Shorty
|
37
|
+
bundle update
|
38
|
+
bundle exec bacon spec/main.rb
|
39
|
+
|
40
|
+
"I hate writing."
|
41
|
+
-----------------------------
|
42
|
+
|
43
|
+
If you know of existing software that makes the above redundant,
|
44
|
+
please tell me. The last thing I want to do is maintain code.
|
45
|
+
|
data/Rakefile
ADDED
data/Shorty.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
$:.push File.expand_path("../lib", __FILE__)
|
4
|
+
require "Shorty/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "Shorty"
|
8
|
+
s.version = Shorty::VERSION
|
9
|
+
s.authors = ["da99"]
|
10
|
+
s.email = ["i-hate-spam-45671204@mailinator.com"]
|
11
|
+
s.homepage = "https://github.com/da99/Shorty"
|
12
|
+
s.summary = %q{A DSL to add before/after hooks to method calls.}
|
13
|
+
s.description = %q{
|
14
|
+
Add before/after hooks to your method calls. More info. at
|
15
|
+
the homepage.
|
16
|
+
}
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.add_development_dependency 'bacon'
|
24
|
+
s.add_development_dependency 'rake'
|
25
|
+
s.add_development_dependency 'Bacon_Colored'
|
26
|
+
s.add_development_dependency 'pry'
|
27
|
+
s.add_development_dependency 'Exit_Zero'
|
28
|
+
|
29
|
+
# Specify any dependencies here; for example:
|
30
|
+
# s.add_runtime_dependency 'rest-client'
|
31
|
+
end
|
data/lib/Shorty.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'Shorty/version'
|
2
|
+
|
3
|
+
class Shorty
|
4
|
+
|
5
|
+
module DSL
|
6
|
+
|
7
|
+
def shortys
|
8
|
+
@shortys ||= Hash[]
|
9
|
+
end
|
10
|
+
|
11
|
+
def befores
|
12
|
+
@befores ||= Hash[]
|
13
|
+
end
|
14
|
+
|
15
|
+
def afters
|
16
|
+
@afters ||= Hash[]
|
17
|
+
end
|
18
|
+
|
19
|
+
def add name, val = :_NONE_
|
20
|
+
if name.is_a?(String) && val == :_NONE_
|
21
|
+
file = File.expand_path(name)
|
22
|
+
(file = "#{file}.rb") unless File.exists?(file)
|
23
|
+
eval File.read(file), nil, file, 1
|
24
|
+
return true
|
25
|
+
end
|
26
|
+
raise ArgumentError, "#{name.inspect} already set" if shortys[name]
|
27
|
+
shortys[name] = val
|
28
|
+
end
|
29
|
+
|
30
|
+
def before name, action, &blok
|
31
|
+
befores[[name, action]] ||= []
|
32
|
+
befores[[name, action]] << blok
|
33
|
+
end
|
34
|
+
|
35
|
+
def after name, action, &blok
|
36
|
+
afters[[name, action]] ||= []
|
37
|
+
afters[[name, action]] << blok
|
38
|
+
end
|
39
|
+
|
40
|
+
def run_hooks group, name, action, package
|
41
|
+
list = group[[name,action]]
|
42
|
+
(list || []).each { |pr|
|
43
|
+
if pr.arity == 0
|
44
|
+
pr.call
|
45
|
+
else
|
46
|
+
pr.call package
|
47
|
+
end
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def run name, action = nil
|
52
|
+
|
53
|
+
r = shortys[name]
|
54
|
+
raise ArgumentError, "#{name.inspect} not found" unless r
|
55
|
+
action ||= :run
|
56
|
+
|
57
|
+
run_hooks befores, name, action, r
|
58
|
+
|
59
|
+
result = if r.is_a?(Proc) && action == :run
|
60
|
+
r.call
|
61
|
+
else
|
62
|
+
r.send action
|
63
|
+
end
|
64
|
+
|
65
|
+
run_hooks afters, name, action, r
|
66
|
+
|
67
|
+
result
|
68
|
+
end # === def package
|
69
|
+
|
70
|
+
def executable? name
|
71
|
+
`which #{name}`.strip.empty?
|
72
|
+
end
|
73
|
+
|
74
|
+
end # === DSL
|
75
|
+
|
76
|
+
include DSL
|
77
|
+
|
78
|
+
end # === class Shorty
|
79
|
+
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.print e.message, "\n"
|
7
|
+
$stderr.print "Run `bundle install` to install missing gems\n"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'bacon'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
|
15
|
+
Bacon.summary_on_exit
|
data/spec/main.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
require File.expand_path('spec/helper')
|
3
|
+
require 'Shorty'
|
4
|
+
require 'Bacon_Colored'
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
|
8
|
+
# ======== Include the tests.
|
9
|
+
if ARGV.size > 1 && ARGV[1, ARGV.size - 1].detect { |a| File.exists?(a) }
|
10
|
+
# Do nothing. Bacon grabs the file.
|
11
|
+
else
|
12
|
+
Dir.glob('spec/tests/*.rb').each { |file|
|
13
|
+
require File.expand_path(file.sub('.rb', '')) if File.file?(file)
|
14
|
+
}
|
15
|
+
end
|
data/spec/tests/DSL.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
|
2
|
+
module My_Box
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def run
|
6
|
+
"My_Box run"
|
7
|
+
end
|
8
|
+
|
9
|
+
def custom
|
10
|
+
"My_Box custom"
|
11
|
+
end
|
12
|
+
|
13
|
+
end # === class
|
14
|
+
end # === My_Box
|
15
|
+
|
16
|
+
describe "Shorty run" do
|
17
|
+
|
18
|
+
before {
|
19
|
+
@s = Shorty.new
|
20
|
+
@s.add :my_box, My_Box
|
21
|
+
}
|
22
|
+
|
23
|
+
it "sets default action to :run" do
|
24
|
+
@s.run(:my_box)
|
25
|
+
.should == "My_Box run"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "runs target action" do
|
29
|
+
@s.run(:my_box, :custom)
|
30
|
+
.should == "My_Box custom"
|
31
|
+
end
|
32
|
+
|
33
|
+
end # === Shorty run
|
34
|
+
|
35
|
+
|
36
|
+
describe "Shorty before" do
|
37
|
+
|
38
|
+
it "runs before hooks before run" do
|
39
|
+
s = Shorty.new
|
40
|
+
t = []
|
41
|
+
s.add :test, lambda { t << :t }
|
42
|
+
s.before :test, :run do
|
43
|
+
t << :b
|
44
|
+
end
|
45
|
+
|
46
|
+
s.run :test
|
47
|
+
t.should == [:b, :t]
|
48
|
+
end
|
49
|
+
|
50
|
+
end # === Shorty before
|
51
|
+
|
52
|
+
|
53
|
+
describe "Shorty after" do
|
54
|
+
|
55
|
+
it "runs after hooks after run" do
|
56
|
+
s = Shorty.new
|
57
|
+
t = []
|
58
|
+
s.add :test, lambda { t << :t }
|
59
|
+
s.after :test, :run do
|
60
|
+
t << :a
|
61
|
+
end
|
62
|
+
|
63
|
+
s.run :test
|
64
|
+
t.should == [:t, :a]
|
65
|
+
end
|
66
|
+
|
67
|
+
end # === Shorty after
|
data/spec/tests/bin.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
bins = Dir.glob("bin/*")
|
3
|
+
|
4
|
+
unless bins.empty?
|
5
|
+
describe "permissions of bin/" do
|
6
|
+
bins.each { |file|
|
7
|
+
it "should chmod 755 for: #{file}" do
|
8
|
+
`stat -c %a #{file}`.strip
|
9
|
+
.should.be == "755"
|
10
|
+
end
|
11
|
+
}
|
12
|
+
end # === permissions of bin/
|
13
|
+
end # === unless bins.empty?
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Shorty
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- da99
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bacon
|
16
|
+
requirement: !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: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: Bacon_Colored
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: pry
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: Exit_Zero
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: ! "\n Add before/after hooks to your method calls. More info. at\n
|
95
|
+
\ the homepage.\n "
|
96
|
+
email:
|
97
|
+
- i-hate-spam-45671204@mailinator.com
|
98
|
+
executables: []
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- Gemfile
|
104
|
+
- README.md
|
105
|
+
- Rakefile
|
106
|
+
- Shorty.gemspec
|
107
|
+
- lib/Shorty.rb
|
108
|
+
- lib/Shorty/version.rb
|
109
|
+
- spec/helper.rb
|
110
|
+
- spec/main.rb
|
111
|
+
- spec/tests/DSL.rb
|
112
|
+
- spec/tests/Shorty.rb
|
113
|
+
- spec/tests/bin.rb
|
114
|
+
homepage: https://github.com/da99/Shorty
|
115
|
+
licenses: []
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 1.8.19
|
135
|
+
signing_key:
|
136
|
+
specification_version: 3
|
137
|
+
summary: A DSL to add before/after hooks to method calls.
|
138
|
+
test_files: []
|