buff-shell_out-1.1.0/0000755000004100000410000000000012766600270014465 5ustar www-datawww-databuff-shell_out-1.1.0/Thorfile0000644000004100000410000000202612766600270016164 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"].invoke end desc "install", "Build and install buff-shell_out-#{Buff::ShellOut::VERSION}.gem into system gems" def install Rake::Task["install"].invoke 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"].invoke 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-1.1.0/Gemfile0000644000004100000410000000004712766600270015761 0ustar www-datawww-datasource 'https://rubygems.org' gemspec buff-shell_out-1.1.0/spec/0000755000004100000410000000000012766600270015417 5ustar www-datawww-databuff-shell_out-1.1.0/spec/buff/0000755000004100000410000000000012766600270016341 5ustar www-datawww-databuff-shell_out-1.1.0/spec/buff/shell_out/0000755000004100000410000000000012766600270020337 5ustar www-datawww-databuff-shell_out-1.1.0/spec/buff/shell_out/response_spec.rb0000644000004100000410000000011212766600270023526 0ustar www-datawww-datarequire 'spec_helper' describe Buff::ShellOut::Response do pending end buff-shell_out-1.1.0/spec/buff/shell_out_spec.rb0000644000004100000410000000276512766600270021710 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 it "has a string for stdout" do expect(subject.stdout).to be_a(String) end it "has a string for stderr" do expect(subject.stderr).to be_a(String) end it "has a fixnum for exitstatus" do expect(subject.exitstatus).to be_a(Fixnum) end it "has a truth value for success?" do expect(subject.success?).to eql(true) end it "has a false value for error?" do expect(subject.error?).to eql(false) end context "when on MRI" do before { allow(described_class).to receive(: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 { allow(Process).to receive(:waitpid2) { [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 { allow(described_class).to receive(: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-1.1.0/spec/spec_helper.rb0000644000004100000410000000100712766600270020233 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.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-1.1.0/.travis.yml0000644000004100000410000000016512766600270016600 0ustar www-datawww-datasudo: false language: ruby branches: only: - master script: "bundle exec thor spec" rvm: - 2.2.5 - 2.3.1 buff-shell_out-1.1.0/lib/0000755000004100000410000000000012766600270015233 5ustar www-datawww-databuff-shell_out-1.1.0/lib/buff/0000755000004100000410000000000012766600270016155 5ustar www-datawww-databuff-shell_out-1.1.0/lib/buff/shell_out/0000755000004100000410000000000012766600270020153 5ustar www-datawww-databuff-shell_out-1.1.0/lib/buff/shell_out/response.rb0000644000004100000410000000114212766600270022334 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-1.1.0/lib/buff/shell_out/version.rb0000644000004100000410000000007612766600270022170 0ustar www-datawww-datamodule Buff module ShellOut VERSION = "1.1.0" end end buff-shell_out-1.1.0/lib/buff/shell_out.rb0000644000004100000410000000460012766600270020500 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-1.1.0/lib/buff-shell_out.rb0000644000004100000410000000004212766600270020472 0ustar www-datawww-datarequire_relative 'buff/shell_out' buff-shell_out-1.1.0/.gitignore0000644000004100000410000000023212766600270016452 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-1.1.0/CONTRIBUTING.md0000644000004100000410000000073012766600270016716 0ustar www-datawww-data# Contributing ## Running tests ### Install prerequisites Install the latest version of [Bundler](http://bundler.io/) ```shell $ gem install bundler ``` Clone the project ```shell $ git clone git://github.com/berkshelf/buff-shell_out.git ``` and run: ```shell $ cd buff-shell_out $ bundle install ``` Bundler will install all gems and their dependencies required for testing and developing. ### Running unit (RSpec) tests ```shell $ bundle exec guard start ``` buff-shell_out-1.1.0/LICENSE0000644000004100000410000000113012766600270015465 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-1.1.0/buff-shell_out.gemspec0000644000004100000410000000254512766600270020756 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/berkshelf/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 = ">= 2.2.0" spec.add_dependency "buff-ruby_engine", "~> 1.0" spec.add_development_dependency "thor", "~> 0.19.1" 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-1.1.0/README.md0000644000004100000410000000223512766600270015746 0ustar www-datawww-data# Buff::ShellOut [![Gem Version](https://badge.fury.io/rb/buff-shell_out.svg)](http://badge.fury.io/rb/buff-shell_out) [![Build Status](https://travis-ci.org/berkshelf/buff-shell_out.svg?branch=master)](https://travis-ci.org/berkshelf/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: ```ruby gem 'buff-shell_out' ``` And then execute: ```shell $ bundle ``` Or install it yourself as: ```shell $ gem install buff-shell_out ``` ## Usage Using it as a mixin: ```ruby 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: ```ruby require 'buff/shell_out' Buff::ShellOut.shell_out("ls") #=> <#Buff::ShellOut::Response @exitstatus=0, @stdout="...", @stderr="..."> ``` # Authors and Contributors - Jamie Winsor ([jamie@vialstudios.com](mailto:jamie@vialstudios.com)) Thank you to all of our [Contributors](https://github.com/berkshelf/buff-shell_out/graphs/contributors), testers, and users. buff-shell_out-1.1.0/Guardfile0000644000004100000410000000070412766600270016313 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