with-env-1.1.0/0000755000175100017510000000000014172737570012315 5ustar pravipraviwith-env-1.1.0/.gitignore0000644000175100017510000000012714172737570014305 0ustar pravipravi/.bundle/ /.yardoc /Gemfile.lock /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ with-env-1.1.0/Rakefile0000644000175100017510000000016514172737570013764 0ustar pravipravirequire "bundler/gem_tasks" require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) task :default => :spec with-env-1.1.0/bin/0000755000175100017510000000000014172737570013065 5ustar pravipraviwith-env-1.1.0/bin/console0000755000175100017510000000051514172737570014456 0ustar pravipravi#!/usr/bin/env ruby require "bundler/setup" require "with_env" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. # (If you use this, don't forget to add pry to your Gemfile!) # require "pry" # Pry.start require "irb" IRB.start with-env-1.1.0/bin/setup0000755000175100017510000000016314172737570014153 0ustar pravipravi#!/bin/bash set -euo pipefail IFS=$'\n\t' bundle install # Do any other automated setup that you need to do here with-env-1.1.0/lib/0000755000175100017510000000000014172737570013063 5ustar pravipraviwith-env-1.1.0/lib/with_env/0000755000175100017510000000000014172737570014706 5ustar pravipraviwith-env-1.1.0/lib/with_env/version.rb0000644000175100017510000000004714172737570016721 0ustar pravipravimodule WithEnv VERSION = "1.1.0" end with-env-1.1.0/lib/with_env.rb0000644000175100017510000000053514172737570015236 0ustar pravipravirequire "with_env/version" module WithEnv extend self def with_env(env, &blk) before = ENV.to_h.dup env.each { |k, v| ENV[k] = v } yield ensure ENV.replace(before) end def without_env(*keys, &blk) before = ENV.to_h.dup keys.flatten.each { |k| ENV.delete(k) } yield ensure ENV.replace(before) end end with-env-1.1.0/README.md0000644000175100017510000000263314172737570013600 0ustar pravipravi# WithEnv WithEnv is an extremely small helper module for executing code with ENV variables. It exists because I got tired of re-writing or copying over a #with_env helper method for the 131st time. ## Installation Add this line to your application's Gemfile: ```ruby gem 'with_env' ``` And then execute: $ bundle Or install it yourself as: $ gem install with_env ## Usage ``` include WithEnv with_env("FOO" => "BAR") do `echo $FOO` # => "BAR\n" ENV["FOO"] # => "BAR" end # The ENV has been restored to what it was before the # above with_env block, so FOO no longer exists `echo $FOO` # => "\n" ENV.has_key?("FOO") # => false ``` ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/mhs/with_env-rb. ## License The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). with-env-1.1.0/.travis.yml0000644000175100017510000000011414172737570014422 0ustar pravipravilanguage: ruby rvm: - 2.1.5 before_install: gem install bundler -v 1.10.5 with-env-1.1.0/with_env.gemspec0000644000175100017510000000222114172737570015502 0ustar pravipravi# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'with_env/version' Gem::Specification.new do |spec| spec.name = "with_env" spec.version = WithEnv::VERSION spec.authors = ["Zach Dennis"] spec.email = ["zach.dennis@gmail.com"] spec.summary = %q{WithEnv is an extremely small helper module for executing code with ENV variables.} spec.description = %q{ WithEnv is an extremely small helper module for executing code with ENV variables. It exists because I got tired of re-writing or copying over a #with_env helper method for the 131st time. } spec.homepage = "https://github.com/mhs/with_env-rb" spec.license = "MIT" spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] spec.add_development_dependency "bundler", "~> 1.10" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rspec", "~> 3" end with-env-1.1.0/Gemfile0000644000175100017510000000013514172737570013607 0ustar pravipravisource 'https://rubygems.org' # Specify your gem's dependencies in with_env.gemspec gemspec with-env-1.1.0/.rspec0000644000175100017510000000003714172737570013432 0ustar pravipravi--format documentation --color with-env-1.1.0/LICENSE.txt0000644000175100017510000000206614172737570014144 0ustar pravipraviThe MIT License (MIT) Copyright (c) 2015 Zach Dennis Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.