buff-shell_out 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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1 @@
1
+ 1.9.3-p429
@@ -0,0 +1,7 @@
1
+ script: "bundle exec thor spec"
2
+ language: ruby
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - jruby-19mode
@@ -0,0 +1,24 @@
1
+ # Contributing
2
+
3
+ ## Running tests
4
+
5
+ ### Install prerequisites
6
+
7
+ Install the latest version of [Bundler](http://gembundler.com)
8
+
9
+ $ gem install bundler
10
+
11
+ Clone the project
12
+
13
+ $ git clone git://github.com/RiotGames/buff-shell_out.git
14
+
15
+ and run:
16
+
17
+ $ cd buff-shell_out
18
+ $ bundle install
19
+
20
+ Bundler will install all gems and their dependencies required for testing and developing.
21
+
22
+ ### Running unit (RSpec) tests
23
+
24
+ $ bundle exec guard start
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,15 @@
1
+ notification :off
2
+
3
+ guard "spork" do
4
+ watch('Gemfile')
5
+ watch('spec/spec_helper.rb') { :rspec }
6
+ watch(%r{^spec/support/.+\.rb$}) { :rspec }
7
+ end
8
+
9
+ guard "rspec", cli: "--color --drb --format Fuubar", all_on_start: false, all_after_pass: false do
10
+ watch(%r{^spec/.+_spec\.rb$})
11
+
12
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
13
+ watch('spec/spec_helper.rb') { "spec" }
14
+ watch(%r{^spec/support/.+\.rb$}) { "spec" }
15
+ end
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Copyright 2012-2013 Riot Games
2
+
3
+ Jamie Winsor (<reset@riotgames.com>)
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
@@ -0,0 +1,44 @@
1
+ # Buff::ShellOut
2
+ [![Gem Version](https://badge.fury.io/rb/buff-shell_out.png)](http://badge.fury.io/rb/buff-shell_out)
3
+ [![Build Status](https://travis-ci.org/RiotGames/buff-shell_out.png?branch=master)](https://travis-ci.org/RiotGames/buff-shell_out)
4
+
5
+ Buff up your code with a mixin for issuing shell commands and collecting the output
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'buff-shell_out'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install buff-shell_out
20
+
21
+ ## Usage
22
+
23
+ Using it as a mixin
24
+
25
+ require 'buff/shell_out'
26
+
27
+ class PowerUp
28
+ include Buff::ShellOut
29
+ end
30
+
31
+ power_up = PowerUp.new
32
+ power_up.shell_out("ls") #=> <#Buff::ShellOut::Response @exitstatus=0, @stdout="...", @stderr="...">
33
+
34
+ Using it as a module
35
+
36
+ require 'buff/shell_out'
37
+
38
+ Buff::ShellOut.shell_out("ls") #=> <#Buff::ShellOut::Response @exitstatus=0, @stdout="...", @stderr="...">
39
+
40
+ # Authors and Contributors
41
+
42
+ * Jamie Winsor (<reset@riotgames.com>)
43
+
44
+ Thank you to all of our [Contributors](https://github.com/RiotGames/buff-shell_out/graphs/contributors), testers, and users.
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ require 'bundler'
5
+ require 'bundler/setup'
6
+ require 'buff/shell_out/version'
7
+ require 'buff/ruby_engine'
8
+
9
+ class Default < Thor
10
+ extend Buff::RubyEngine
11
+
12
+ unless jruby?
13
+ require 'thor/rake_compat'
14
+
15
+ include Thor::RakeCompat
16
+ Bundler::GemHelper.install_tasks
17
+
18
+ desc "build", "Build buff-shell_out-#{Buff::ShellOut::VERSION}.gem into the pkg directory"
19
+ def build
20
+ Rake::Task["build"].execute
21
+ end
22
+
23
+ desc "install", "Build and install buff-shell_out-#{Buff::ShellOut::VERSION}.gem into system gems"
24
+ def install
25
+ Rake::Task["install"].execute
26
+ end
27
+
28
+ desc "release", "Create tag v#{Buff::ShellOut::VERSION} and build and push buff-shell_out-#{Buff::ShellOut::VERSION}.gem to Rubygems"
29
+ def release
30
+ Rake::Task["release"].execute
31
+ end
32
+ end
33
+
34
+ class Spec < Thor
35
+ namespace :spec
36
+ default_task :unit
37
+
38
+ desc "unit", "run the project's unit tests"
39
+ def unit
40
+ exec "rspec --color --format=documentation spec"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'buff/shell_out/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "buff-shell_out"
8
+ spec.version = Buff::ShellOut::VERSION
9
+ spec.authors = ["Jamie Winsor"]
10
+ spec.email = ["reset@riotgames.com"]
11
+ spec.description = %q{A mixin for issuing shell commands and collecting the output}
12
+ spec.summary = %q{Buff up your code with a mixin for issuing shell commands and collecting the output}
13
+ spec.homepage = "https://github.com/RiotGames/buff-shell_out"
14
+ spec.license = "Apache 2.0"
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{^spec/})
19
+ spec.require_paths = ["lib"]
20
+ spec.required_ruby_version = ">= 1.9.2"
21
+
22
+ spec.add_dependency "buff-ruby_engine", "~> 0.1.0"
23
+
24
+ spec.add_development_dependency "thor", "~> 0.18.0"
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "fuubar"
29
+ spec.add_development_dependency "guard"
30
+ spec.add_development_dependency "guard-rspec"
31
+ spec.add_development_dependency "guard-spork"
32
+ spec.add_development_dependency "spork"
33
+ end
@@ -0,0 +1 @@
1
+ require_relative 'buff/shell_out'
@@ -0,0 +1,63 @@
1
+ require 'tempfile'
2
+ require 'buff/ruby_engine'
3
+
4
+ # A Ruby platform agnostic way of executing shell commands on the local system
5
+ module Buff
6
+ module ShellOut
7
+ require_relative 'shell_out/version'
8
+ require_relative 'shell_out/response'
9
+
10
+ include Buff::RubyEngine
11
+ extend self
12
+
13
+ # Executes the given shell command on the local system
14
+ #
15
+ # @param [String] command
16
+ # The command to execute
17
+ #
18
+ # @return [ShellOut::Response]
19
+ def shell_out(command)
20
+ process_status, out, err = jruby? ? jruby_out(command) : mri_out(command)
21
+ Response.new(process_status, out, err)
22
+ end
23
+
24
+ private
25
+
26
+ # @param [String] command
27
+ # The command to execute
28
+ def mri_out(command)
29
+ out, err = Tempfile.new('mixin.shell_out.stdout'), Tempfile.new('mixin.shell_out.stderr')
30
+
31
+ begin
32
+ pid = Process.spawn(command, out: out.to_i, err: err.to_i)
33
+ pid, status = Process.waitpid2(pid)
34
+ exitstatus = status.exitstatus
35
+ rescue Errno::ENOENT => ex
36
+ exitstatus = 127
37
+ out.write("")
38
+ err.write("command not found: #{command}")
39
+ end
40
+
41
+ out.close
42
+ err.close
43
+
44
+ [ exitstatus, File.read(out), File.read(err) ]
45
+ end
46
+
47
+ # @param [String] command
48
+ # The command to execute
49
+ def jruby_out(command)
50
+ out, err = StringIO.new, StringIO.new
51
+ $stdout, $stderr = out, err
52
+ system(command)
53
+
54
+ exitstatus = $?.exitstatus
55
+ out.rewind
56
+ err.rewind
57
+
58
+ [ exitstatus, out.read, err.read ]
59
+ ensure
60
+ $stdout, $stderr = STDOUT, STDERR
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,30 @@
1
+ module Buff
2
+ module ShellOut
3
+ class Response
4
+ # @return [Fixnum]
5
+ attr_reader :exitstatus
6
+ # @return [String]
7
+ attr_reader :stdout
8
+ # @return [String]
9
+ attr_reader :stderr
10
+
11
+ # @param [Fixnum] exitstatus
12
+ # @param [String] stdout
13
+ # @param [String] stderr
14
+ def initialize(exitstatus, stdout, stderr)
15
+ @exitstatus = exitstatus
16
+ @stdout = stdout
17
+ @stderr = stderr
18
+ end
19
+
20
+ def success?
21
+ exitstatus == 0
22
+ end
23
+
24
+ def error?
25
+ !success?
26
+ end
27
+ alias_method :failure?, :error?
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module Buff
2
+ module ShellOut
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Buff::ShellOut::Response do
4
+ pending
5
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Buff::ShellOut do
4
+ describe "#shell_out" do
5
+ let(:command) { "ls" }
6
+
7
+ subject(:result) { described_class.shell_out(command) }
8
+
9
+ it "returns a ShellOut::Response" do
10
+ expect(result).to be_a(described_class::Response)
11
+ end
12
+
13
+ its(:stdout) { should be_a(String) }
14
+ its(:stderr) { should be_a(String) }
15
+ its(:exitstatus) { should be_a(Fixnum) }
16
+ its(:success?) { should be_true }
17
+ its(:error?) { should be_false }
18
+
19
+ context "when on MRI" do
20
+ before { described_class.stub(jruby?: false) }
21
+
22
+ it "delegates to #mri_out" do
23
+ described_class.should_receive(:mri_out).with(command)
24
+ result
25
+ end
26
+ end
27
+
28
+ context "when on JRuby" do
29
+ before { described_class.stub(jruby?: true) }
30
+
31
+ it "delegates to #jruby_out" do
32
+ described_class.should_receive(:jruby_out).with(command)
33
+ result
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,27 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'rspec'
4
+ require 'buff/ruby_engine'
5
+
6
+ def setup_rspec
7
+ RSpec.configure do |config|
8
+ config.expect_with :rspec do |c|
9
+ c.syntax = :expect
10
+ end
11
+
12
+ config.mock_with :rspec
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.filter_run focus: true
15
+ config.run_all_when_everything_filtered = true
16
+ end
17
+ end
18
+
19
+ if Buff::RubyEngine.jruby?
20
+ require 'buff/shell_out'
21
+ setup_rspec
22
+ else
23
+ require 'spork'
24
+
25
+ Spork.prefork { setup_rspec }
26
+ Spork.each_run { require 'buff/shell_out' }
27
+ end
metadata ADDED
@@ -0,0 +1,230 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buff-shell_out
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jamie Winsor
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: buff-ruby_engine
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: thor
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.18.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.18.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
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: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
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: rspec
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
+ - !ruby/object:Gem::Dependency
95
+ name: fuubar
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: guard
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: guard-rspec
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: guard-spork
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: spork
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ description: A mixin for issuing shell commands and collecting the output
175
+ email:
176
+ - reset@riotgames.com
177
+ executables: []
178
+ extensions: []
179
+ extra_rdoc_files: []
180
+ files:
181
+ - .gitignore
182
+ - .ruby-version
183
+ - .travis.yml
184
+ - CONTRIBUTING.md
185
+ - Gemfile
186
+ - Guardfile
187
+ - LICENSE
188
+ - README.md
189
+ - Thorfile
190
+ - buff-shell_out.gemspec
191
+ - lib/buff-shell_out.rb
192
+ - lib/buff/shell_out.rb
193
+ - lib/buff/shell_out/response.rb
194
+ - lib/buff/shell_out/version.rb
195
+ - spec/buff/shell_out/response_spec.rb
196
+ - spec/buff/shell_out_spec.rb
197
+ - spec/spec_helper.rb
198
+ homepage: https://github.com/RiotGames/buff-shell_out
199
+ licenses:
200
+ - Apache 2.0
201
+ post_install_message:
202
+ rdoc_options: []
203
+ require_paths:
204
+ - lib
205
+ required_ruby_version: !ruby/object:Gem::Requirement
206
+ none: false
207
+ requirements:
208
+ - - ! '>='
209
+ - !ruby/object:Gem::Version
210
+ version: 1.9.2
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
212
+ none: false
213
+ requirements:
214
+ - - ! '>='
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
217
+ segments:
218
+ - 0
219
+ hash: 3711137622216531874
220
+ requirements: []
221
+ rubyforge_project:
222
+ rubygems_version: 1.8.23
223
+ signing_key:
224
+ specification_version: 3
225
+ summary: Buff up your code with a mixin for issuing shell commands and collecting
226
+ the output
227
+ test_files:
228
+ - spec/buff/shell_out/response_spec.rb
229
+ - spec/buff/shell_out_spec.rb
230
+ - spec/spec_helper.rb