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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f20e93081ed84a57df274ce99797d4aba409c43e
4
- data.tar.gz: f075c2159472292ee1cb0f6cae1927b06cb2a8a8
3
+ metadata.gz: f8a8c002275b3c0420bf6a8100926ca2c3f040e5
4
+ data.tar.gz: 152e605c97313504941167cbfe8e4885263bc707
5
5
  SHA512:
6
- metadata.gz: 0b8619568bf00163da213ee8bd4ea5480d582101b9dcc7916fb9a4cca4032126682f27488b23694f2897d274b8dd8a0710adea06ee9ae4c7616ec0c8740c4fc8
7
- data.tar.gz: 76cde8fe434e75b2101bf13d92cc3a96d095141aeb08a6cd78017c6f09d56d5f7c6627660ef8f8810638a62df88d8f5d079f79c6b6c3f198e1ca80a8130aaa67
6
+ metadata.gz: 66e18fc1a6c2cb94f2e20555b115fc50019e9779c1f0ef5d04e22125917010ac510fc605f6dd3d1d2d3ec080dbf73aad28a30a53a9f672583dd07b838c6ad3dd
7
+ data.tar.gz: 1654140af0a517d8e8de470f2f1df31b02db1806a06189e9b914abb6f39c7338a2c62f681e15c47bc31d09491dfec6f485384d54316c6cb809a97b122d5f33df
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.0.0
5
+ - 1.9.3
6
+ - jruby-19mode
7
+ - rbx
8
+ cache: bundler
@@ -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
@@ -1,4 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in duct.gemspec
4
3
  gemspec
4
+
5
+ gem 'rubysl-singleton', platform: 'rbx'
@@ -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
- changes.
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
 
@@ -20,7 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "bundler"
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.3"
24
23
  spec.add_development_dependency "rake"
25
24
  spec.add_development_dependency "rspec"
26
25
  end
@@ -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
- @script, @data = File.read(@config.filename).split(/^__END__$/, 2)
9
- @preamble = @data.split(/^@@\s*(.*\S)\s*$/, 2).first
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 "BUNDLE_GEMFILE=#{tempdir}/Gemfile bundle exec ruby #{@config.filename} #{@config.params.join(' ')}; rm -rf #{tempdir}" unless @config.command
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 = @script.dup
49
+ contents = script.dup
29
50
 
30
51
  contents << "__END__"
31
- contents << @preamble
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
- @data.each_line do |line|
65
+ data.each_line do |line|
45
66
  if line =~ /^@@\s*(.*\S)\s*$/
46
67
  file = ''
47
68
  files[$1.to_sym] = file
@@ -1,3 +1,3 @@
1
1
  module Duct
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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.0
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: 2014-01-13 00:00:00.000000000 Z
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.0.3
100
+ rubygems_version: 2.4.5
112
101
  signing_key:
113
102
  specification_version: 4
114
103
  summary: Embeds a Gemfile in a script