duct 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.travis.yml +8 -0
- data/CHANGELOG.md +17 -0
- data/Gemfile +2 -1
- data/Gemfile.lock +32 -0
- data/README.md +18 -3
- data/duct.gemspec +0 -1
- data/lib/duct/runner.rb +27 -6
- data/lib/duct/version.rb +1 -1
- data/spec/unit/cli_spec.rb +20 -0
- metadata +15 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8a8c002275b3c0420bf6a8100926ca2c3f040e5
|
4
|
+
data.tar.gz: 152e605c97313504941167cbfe8e4885263bc707
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66e18fc1a6c2cb94f2e20555b115fc50019e9779c1f0ef5d04e22125917010ac510fc605f6dd3d1d2d3ec080dbf73aad28a30a53a9f672583dd07b838c6ad3dd
|
7
|
+
data.tar.gz: 1654140af0a517d8e8de470f2f1df31b02db1806a06189e9b914abb6f39c7338a2c62f681e15c47bc31d09491dfec6f485384d54316c6cb809a97b122d5f33df
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). Based on the format proposed by [Keep a Changelog](http://keepachangelog.com/).
|
4
|
+
|
5
|
+
## [0.1.1] [2015-10-04]
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
* This change log :)
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
|
13
|
+
* Fixed bug that didn't allow scripts with a space in the filename (thanks @ZimbiX)
|
14
|
+
|
15
|
+
## [0.1.0] [2014-01-13]
|
16
|
+
|
17
|
+
Initial release
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
duct (0.1.1)
|
5
|
+
bundler
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.2.5)
|
11
|
+
rake (10.1.1)
|
12
|
+
rspec (2.14.1)
|
13
|
+
rspec-core (~> 2.14.0)
|
14
|
+
rspec-expectations (~> 2.14.0)
|
15
|
+
rspec-mocks (~> 2.14.0)
|
16
|
+
rspec-core (2.14.7)
|
17
|
+
rspec-expectations (2.14.4)
|
18
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
19
|
+
rspec-mocks (2.14.4)
|
20
|
+
rubysl-singleton (2.0.0)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
duct!
|
27
|
+
rake
|
28
|
+
rspec
|
29
|
+
rubysl-singleton
|
30
|
+
|
31
|
+
BUNDLED WITH
|
32
|
+
1.10.6
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Duct
|
1
|
+
# Duct [![Build Status](https://travis-ci.org/porras/duct.png?branch=master)](https://travis-ci.org/porras/duct)
|
2
2
|
|
3
3
|
![Duct Tape, By Evan-Amos, via Wikimedia Commons](http://upload.wikimedia.org/wikipedia/commons/thumb/8/89/Duct-tape.jpg/256px-Duct-tape.jpg)
|
4
4
|
|
@@ -70,8 +70,23 @@ filename:
|
|
70
70
|
$ duct update sinatra my_script.rb
|
71
71
|
```
|
72
72
|
|
73
|
-
Remember that updating the bundle will update the `Gemfile.lock` section in your script, so remember to save those
|
74
|
-
|
73
|
+
Remember that updating the bundle will update the `Gemfile.lock` section in your script, so remember to save those changes.
|
74
|
+
|
75
|
+
### Using Duct in shebangs
|
76
|
+
|
77
|
+
Under Unix-like operating systems, you can instruct the program loader to use Duct to run your script. Just put the following [shebang](http://en.wikipedia.org/wiki/Shebang_(Unix)) in the first line of your script (the `# ruby` comment is needed because of something explained [here](http://devoh.com/blog/2012/11/local-environment-variables)):
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
#!/usr/bin/env duct # ruby
|
81
|
+
```
|
82
|
+
and add execute permissions to your script:
|
83
|
+
|
84
|
+
```zsh
|
85
|
+
chmod +x my_script
|
86
|
+
```
|
87
|
+
|
88
|
+
This gives you the ability to treat your script as an executable that, once in your $PATH, to execute it directly.
|
89
|
+
|
75
90
|
|
76
91
|
### Using the script data
|
77
92
|
|
data/duct.gemspec
CHANGED
data/lib/duct/runner.rb
CHANGED
@@ -1,19 +1,40 @@
|
|
1
1
|
require 'tmpdir'
|
2
2
|
require 'stringio'
|
3
|
+
require 'shellwords'
|
3
4
|
|
4
5
|
module Duct
|
5
6
|
class Runner
|
6
7
|
def initialize(config)
|
7
8
|
@config = config
|
8
|
-
|
9
|
-
|
9
|
+
end
|
10
|
+
|
11
|
+
def file_content
|
12
|
+
@file_content ||= File.read(@config.filename).split(/^__END__$/, 2)
|
13
|
+
end
|
14
|
+
|
15
|
+
def script
|
16
|
+
@script ||= file_content.first
|
17
|
+
end
|
18
|
+
|
19
|
+
def data
|
20
|
+
@data ||= file_content.last
|
21
|
+
end
|
22
|
+
|
23
|
+
def preamble
|
24
|
+
@preamble ||= data.split(/^@@\s*(.*\S)\s*$/, 2).first
|
10
25
|
end
|
11
26
|
|
12
27
|
def run
|
13
28
|
copy_embedded_files
|
14
29
|
system "BUNDLE_GEMFILE=#{tempdir}/Gemfile bundle #{@config.command}"
|
15
30
|
update_embedded_files
|
16
|
-
exec
|
31
|
+
exec script_command unless @config.command
|
32
|
+
end
|
33
|
+
|
34
|
+
def script_command
|
35
|
+
filename = @config.filename.shellescape
|
36
|
+
params = @config.params.join(' ')
|
37
|
+
"BUNDLE_GEMFILE=#{tempdir}/Gemfile bundle exec ruby #{filename} #{params}; rm -rf #{tempdir}"
|
17
38
|
end
|
18
39
|
|
19
40
|
private
|
@@ -25,10 +46,10 @@ module Duct
|
|
25
46
|
end
|
26
47
|
|
27
48
|
def update_embedded_files
|
28
|
-
contents =
|
49
|
+
contents = script.dup
|
29
50
|
|
30
51
|
contents << "__END__"
|
31
|
-
contents <<
|
52
|
+
contents << preamble
|
32
53
|
|
33
54
|
Dir.glob("#{tempdir}/*") do |filename|
|
34
55
|
contents << "@@ #{File.basename(filename)}\n"
|
@@ -41,7 +62,7 @@ module Duct
|
|
41
62
|
def embedded_files
|
42
63
|
@embedded_files ||= {}.tap do |files|
|
43
64
|
file = nil
|
44
|
-
|
65
|
+
data.each_line do |line|
|
45
66
|
if line =~ /^@@\s*(.*\S)\s*$/
|
46
67
|
file = ''
|
47
68
|
files[$1.to_sym] = file
|
data/lib/duct/version.rb
CHANGED
data/spec/unit/cli_spec.rb
CHANGED
@@ -13,6 +13,15 @@ describe Duct::Cli do
|
|
13
13
|
its(:error?) { should be_false }
|
14
14
|
end
|
15
15
|
|
16
|
+
context 'filename with space' do
|
17
|
+
let(:argv) { ['myscript space.rb'] }
|
18
|
+
|
19
|
+
its(:filename) { should == 'myscript space.rb' }
|
20
|
+
its(:command) { should be_nil }
|
21
|
+
its(:params) { should be_empty }
|
22
|
+
its(:error?) { should be_false }
|
23
|
+
end
|
24
|
+
|
16
25
|
context 'filename and params' do
|
17
26
|
let(:argv) { ['myscript.rb', 'param1', 'param2'] }
|
18
27
|
|
@@ -20,6 +29,17 @@ describe Duct::Cli do
|
|
20
29
|
its(:command) { should be_nil }
|
21
30
|
its(:params) { should == ['param1', 'param2'] }
|
22
31
|
its(:error?) { should be_false }
|
32
|
+
its('runner.script_command') { should match(%r{.+ruby myscript.rb param1 param2.+}) }
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'filename with space and params' do
|
36
|
+
let(:argv) { ['myscript space.rb', 'param1', 'param2'] }
|
37
|
+
|
38
|
+
its(:filename) { should == 'myscript space.rb' }
|
39
|
+
its(:command) { should be_nil }
|
40
|
+
its(:params) { should == ['param1', 'param2'] }
|
41
|
+
its(:error?) { should be_false }
|
42
|
+
its('runner.script_command') { should match(%r{.+ruby myscript\\ space.rb param1 param2.+}) }
|
23
43
|
end
|
24
44
|
|
25
45
|
context 'command and filename' do
|
metadata
CHANGED
@@ -1,69 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergio Gil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ~>
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.3'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ~>
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.3'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rake
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
|
-
- -
|
31
|
+
- - ">="
|
46
32
|
- !ruby/object:Gem::Version
|
47
33
|
version: '0'
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
|
-
- -
|
38
|
+
- - ">="
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rspec
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
|
-
- -
|
45
|
+
- - ">="
|
60
46
|
- !ruby/object:Gem::Version
|
61
47
|
version: '0'
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
|
-
- -
|
52
|
+
- - ">="
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '0'
|
69
55
|
description: Embeds a Gemfile in a script
|
@@ -74,8 +60,11 @@ executables:
|
|
74
60
|
extensions: []
|
75
61
|
extra_rdoc_files: []
|
76
62
|
files:
|
77
|
-
- .gitignore
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CHANGELOG.md
|
78
66
|
- Gemfile
|
67
|
+
- Gemfile.lock
|
79
68
|
- LICENSE.txt
|
80
69
|
- README.md
|
81
70
|
- Rakefile
|
@@ -98,17 +87,17 @@ require_paths:
|
|
98
87
|
- lib
|
99
88
|
required_ruby_version: !ruby/object:Gem::Requirement
|
100
89
|
requirements:
|
101
|
-
- -
|
90
|
+
- - ">="
|
102
91
|
- !ruby/object:Gem::Version
|
103
92
|
version: '0'
|
104
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
94
|
requirements:
|
106
|
-
- -
|
95
|
+
- - ">="
|
107
96
|
- !ruby/object:Gem::Version
|
108
97
|
version: '0'
|
109
98
|
requirements: []
|
110
99
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.
|
100
|
+
rubygems_version: 2.4.5
|
112
101
|
signing_key:
|
113
102
|
specification_version: 4
|
114
103
|
summary: Embeds a Gemfile in a script
|