buff-shell_out-0.2.0/0000755000004100000410000000000012560600773014465 5ustar www-datawww-databuff-shell_out-0.2.0/Thorfile0000644000004100000410000000203112560600773016160 0ustar www-datawww-data# encoding: utf-8 $:.push File.expand_path("../lib", __FILE__) require 'bundler' require 'bundler/setup' require 'buff/shell_out/version' require 'buff/ruby_engine' class Default < Thor extend Buff::RubyEngine unless jruby? require 'thor/rake_compat' include Thor::RakeCompat Bundler::GemHelper.install_tasks desc "build", "Build buff-shell_out-#{Buff::ShellOut::VERSION}.gem into the pkg directory" def build Rake::Task["build"].execute end desc "install", "Build and install buff-shell_out-#{Buff::ShellOut::VERSION}.gem into system gems" def install Rake::Task["install"].execute end desc "release", "Create tag v#{Buff::ShellOut::VERSION} and build and push buff-shell_out-#{Buff::ShellOut::VERSION}.gem to Rubygems" def release Rake::Task["release"].execute end end class Spec < Thor namespace :spec default_task :unit desc "unit", "run the project's unit tests" def unit exec "rspec --color --format=documentation spec" end end end buff-shell_out-0.2.0/Gemfile0000644000004100000410000000004712560600773015761 0ustar www-datawww-datasource 'https://rubygems.org' gemspec buff-shell_out-0.2.0/.ruby-version0000644000004100000410000000001312560600773017124 0ustar www-datawww-data1.9.3-p448 buff-shell_out-0.2.0/spec/0000755000004100000410000000000012560600773015417 5ustar www-datawww-databuff-shell_out-0.2.0/spec/buff/0000755000004100000410000000000012560600773016341 5ustar www-datawww-databuff-shell_out-0.2.0/spec/buff/shell_out/0000755000004100000410000000000012560600773020337 5ustar www-datawww-databuff-shell_out-0.2.0/spec/buff/shell_out/response_spec.rb0000644000004100000410000000011212560600773023526 0ustar www-datawww-datarequire 'spec_helper' describe Buff::ShellOut::Response do pending end buff-shell_out-0.2.0/spec/buff/shell_out_spec.rb0000644000004100000410000000230612560600773021677 0ustar www-datawww-datarequire 'spec_helper' describe Buff::ShellOut do describe "#shell_out" do let(:command) { "ls" } subject(:result) { described_class.shell_out(command) } it "returns a ShellOut::Response" do expect(result).to be_a(described_class::Response) end its(:stdout) { should be_a(String) } its(:stderr) { should be_a(String) } its(:exitstatus) { should be_a(Fixnum) } its(:success?) { should be_true } its(:error?) { should be_false } context "when on MRI" do before { described_class.stub(jruby?: false) } it "delegates to #mri_out" do expect(described_class).to receive(:mri_out).with(command, {}) result end context "when Process.waitpid2 returns an Integer instead of a Process::Status" do before { Process.stub(:waitpid2).and_return([12345, 0]) } it "sets the exitstatus to the returned integer" do expect(result.exitstatus).to eql(0) end end end context "when on JRuby" do before { described_class.stub(jruby?: true) } it "delegates to #jruby_out" do expect(described_class).to receive(:jruby_out).with(command, {}) result end end end end buff-shell_out-0.2.0/spec/spec_helper.rb0000644000004100000410000000111112560600773020227 0ustar www-datawww-data$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'rspec' require 'buff/ruby_engine' def setup_rspec RSpec.configure do |config| config.expect_with :rspec do |c| c.syntax = :expect end config.mock_with :rspec config.treat_symbols_as_metadata_keys_with_true_values = true config.filter_run focus: true config.run_all_when_everything_filtered = true end end if Buff::RubyEngine.jruby? require 'buff/shell_out' setup_rspec else require 'spork' Spork.prefork { setup_rspec } Spork.each_run { require 'buff/shell_out' } end buff-shell_out-0.2.0/.travis.yml0000644000004100000410000000014312560600773016574 0ustar www-datawww-datascript: "bundle exec thor spec" language: ruby rvm: - 1.9.2 - 1.9.3 - 2.0.0 - jruby-19mode buff-shell_out-0.2.0/lib/0000755000004100000410000000000012560600773015233 5ustar www-datawww-databuff-shell_out-0.2.0/lib/buff/0000755000004100000410000000000012560600773016155 5ustar www-datawww-databuff-shell_out-0.2.0/lib/buff/shell_out/0000755000004100000410000000000012560600773020153 5ustar www-datawww-databuff-shell_out-0.2.0/lib/buff/shell_out/response.rb0000644000004100000410000000114212560600773022334 0ustar www-datawww-datamodule Buff module ShellOut class Response # @return [Fixnum] attr_reader :exitstatus # @return [String] attr_reader :stdout # @return [String] attr_reader :stderr # @param [Fixnum] exitstatus # @param [String] stdout # @param [String] stderr def initialize(exitstatus, stdout, stderr) @exitstatus = exitstatus @stdout = stdout @stderr = stderr end def success? exitstatus == 0 end def error? !success? end alias_method :failure?, :error? end end end buff-shell_out-0.2.0/lib/buff/shell_out/version.rb0000644000004100000410000000007612560600773022170 0ustar www-datawww-datamodule Buff module ShellOut VERSION = "0.2.0" end end buff-shell_out-0.2.0/lib/buff/shell_out.rb0000644000004100000410000000460012560600773020500 0ustar www-datawww-datarequire 'tempfile' require 'buff/ruby_engine' # A Ruby platform agnostic way of executing shell commands on the local system module Buff module ShellOut require_relative 'shell_out/version' require_relative 'shell_out/response' include Buff::RubyEngine extend self # Executes the given shell command on the local system # # @param [String] command # The command to execute # @param [Hash] env # A hash of enviroment variables to set during execution # # @return [ShellOut::Response] def shell_out(command, env = {}) env = process_env_vars(env) process_status, out, err = jruby? ? jruby_out(command, env) : mri_out(command, env) Response.new(process_status, out, err) end private # @param [String] command # The command to execute def mri_out(command, env = {}) out, err = Tempfile.new('mixin.shell_out.stdout'), Tempfile.new('mixin.shell_out.stderr') begin pid = Process.spawn(env, command, out: out.to_i, err: err.to_i) pid, status = Process.waitpid2(pid) # Check if we're getting back a process status because win32-process 6.x was a fucking MURDERER. # https://github.com/djberg96/win32-process/blob/master/lib/win32/process.rb#L494-L519 exitstatus = status.is_a?(Process::Status) ? status.exitstatus : status rescue Errno::ENOENT => ex exitstatus = 127 out.write("") err.write("command not found: #{command}") end out.close err.close [ exitstatus, File.read(out), File.read(err) ] end # @param [String] command # The command to execute def jruby_out(command, env = {}) out, err = StringIO.new, StringIO.new $stdout, $stderr = out, err system(env, command) exitstatus = $?.exitstatus out.rewind err.rewind [ exitstatus, out.read, err.read ] ensure $stdout, $stderr = STDOUT, STDERR end # Builds a new hash from the given vars hash. The new hash's keys are all uppercase # strings representing environment variables. # # @param [Hash] vars # A hash of environment variables def process_env_vars(vars) vars.inject({}) do |acc, (key, val)| acc[key.to_s.upcase] = val acc end end end end buff-shell_out-0.2.0/lib/buff-shell_out.rb0000644000004100000410000000004212560600773020472 0ustar www-datawww-datarequire_relative 'buff/shell_out' buff-shell_out-0.2.0/metadata.yml0000644000004100000410000001257512560600773017002 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: buff-shell_out version: !ruby/object:Gem::Version version: 0.2.0 prerelease: platform: ruby authors: - Jamie Winsor autorequire: bindir: bin cert_chain: [] date: 2014-08-11 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: buff-ruby_engine requirement: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: 0.1.0 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: 0.1.0 - !ruby/object:Gem::Dependency name: thor requirement: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: 0.18.0 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: 0.18.0 - !ruby/object:Gem::Dependency name: bundler requirement: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '1.3' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '1.3' - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rspec requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: fuubar requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: guard requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: guard-rspec requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: guard-spork requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: spork requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' description: A mixin for issuing shell commands and collecting the output email: - jamie@vialstudios.com executables: [] extensions: [] extra_rdoc_files: [] files: - .gitignore - .ruby-version - .travis.yml - CONTRIBUTING.md - Gemfile - Guardfile - LICENSE - README.md - Thorfile - buff-shell_out.gemspec - lib/buff-shell_out.rb - lib/buff/shell_out.rb - lib/buff/shell_out/response.rb - lib/buff/shell_out/version.rb - spec/buff/shell_out/response_spec.rb - spec/buff/shell_out_spec.rb - spec/spec_helper.rb homepage: https://github.com/RiotGames/buff-shell_out licenses: - Apache 2.0 post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: 1.9.2 required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' segments: - 0 hash: -1099429043491521833 requirements: [] rubyforge_project: rubygems_version: 1.8.23 signing_key: specification_version: 3 summary: Buff up your code with a mixin for issuing shell commands and collecting the output test_files: - spec/buff/shell_out/response_spec.rb - spec/buff/shell_out_spec.rb - spec/spec_helper.rb buff-shell_out-0.2.0/.gitignore0000644000004100000410000000023212560600773016452 0ustar www-datawww-data*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp buff-shell_out-0.2.0/CONTRIBUTING.md0000644000004100000410000000067312560600773016724 0ustar www-datawww-data# Contributing ## Running tests ### Install prerequisites Install the latest version of [Bundler](http://gembundler.com) $ gem install bundler Clone the project $ git clone git://github.com/RiotGames/buff-shell_out.git and run: $ cd buff-shell_out $ bundle install Bundler will install all gems and their dependencies required for testing and developing. ### Running unit (RSpec) tests $ bundle exec guard start buff-shell_out-0.2.0/LICENSE0000644000004100000410000000113012560600773015465 0ustar www-datawww-dataCopyright 2012-2013 Riot Games Jamie Winsor () Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. buff-shell_out-0.2.0/buff-shell_out.gemspec0000644000004100000410000000254712560600773020760 0ustar www-datawww-data# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'buff/shell_out/version' Gem::Specification.new do |spec| spec.name = "buff-shell_out" spec.version = Buff::ShellOut::VERSION spec.authors = ["Jamie Winsor"] spec.email = ["jamie@vialstudios.com"] spec.description = %q{A mixin for issuing shell commands and collecting the output} spec.summary = %q{Buff up your code with a mixin for issuing shell commands and collecting the output} spec.homepage = "https://github.com/RiotGames/buff-shell_out" spec.license = "Apache 2.0" spec.files = `git ls-files`.split($/) spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^spec/}) spec.require_paths = ["lib"] spec.required_ruby_version = ">= 1.9.2" spec.add_dependency "buff-ruby_engine", "~> 0.1.0" spec.add_development_dependency "thor", "~> 0.18.0" spec.add_development_dependency "bundler", "~> 1.3" spec.add_development_dependency "rake" spec.add_development_dependency "rspec" spec.add_development_dependency "fuubar" spec.add_development_dependency "guard" spec.add_development_dependency "guard-rspec" spec.add_development_dependency "guard-spork" spec.add_development_dependency "spork" end buff-shell_out-0.2.0/README.md0000644000004100000410000000215212560600773015744 0ustar www-datawww-data# Buff::ShellOut [![Gem Version](https://badge.fury.io/rb/buff-shell_out.png)](http://badge.fury.io/rb/buff-shell_out) [![Build Status](https://travis-ci.org/RiotGames/buff-shell_out.png?branch=master)](https://travis-ci.org/RiotGames/buff-shell_out) Buff up your code with a mixin for issuing shell commands and collecting the output ## Installation Add this line to your application's Gemfile: gem 'buff-shell_out' And then execute: $ bundle Or install it yourself as: $ gem install buff-shell_out ## Usage Using it as a mixin require 'buff/shell_out' class PowerUp include Buff::ShellOut end power_up = PowerUp.new power_up.shell_out("ls") #=> <#Buff::ShellOut::Response @exitstatus=0, @stdout="...", @stderr="..."> Using it as a module require 'buff/shell_out' Buff::ShellOut.shell_out("ls") #=> <#Buff::ShellOut::Response @exitstatus=0, @stdout="...", @stderr="..."> # Authors and Contributors * Jamie Winsor () Thank you to all of our [Contributors](https://github.com/RiotGames/buff-shell_out/graphs/contributors), testers, and users. buff-shell_out-0.2.0/Guardfile0000644000004100000410000000070412560600773016313 0ustar www-datawww-datanotification :off guard "spork" do watch('Gemfile') watch('spec/spec_helper.rb') { :rspec } watch(%r{^spec/support/.+\.rb$}) { :rspec } end guard "rspec", cli: "--color --drb --format Fuubar", all_on_start: false, all_after_pass: false do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } watch('spec/spec_helper.rb') { "spec" } watch(%r{^spec/support/.+\.rb$}) { "spec" } end