komenda 0.1.3 → 0.1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f61bfb2ae2678d1a23fb5730df34bfb4da84246
4
- data.tar.gz: 389179e3dc70aef14515646e2524d8ee3821fc33
3
+ metadata.gz: 80c7a7ea911cf08c74bd57d47c5d29f2e3200b66
4
+ data.tar.gz: f78bddae9c9776b3103c0c488447416ffc86cebf
5
5
  SHA512:
6
- metadata.gz: 5d4c8315300bd7b46cf1944cba8fa2484bf28666ae2663da1db0ecd20dce44b06cb21beb85f9866be9bb59c03be14118603bf1d7c31cb83d1d0639459e0a7880
7
- data.tar.gz: ca3a6b8d2fe921315c931439545bdeb3351d3245975a313e91f8a110a2ed73460912ddf5fcd992dadff780e1754de75e263ed2950f760e998c45ef15d5b28721
6
+ metadata.gz: 41ca723a231269e4b5c67d715a8f9415ef15cbfadc3a45bdb84aa8540d4b8fd1784e9ffe63ca25f5edefb3c1745a64f3ef770b20f92c2a43058b29694a31fc23
7
+ data.tar.gz: 355cb97d2e3d2c9aafcf09e423358c09883ab8c1ce06bb980777cb5cb4c0aadb8111fc3118985aa466bfe0434323d99d19d6faa2eae2f9cc676e592a1cb13ca8
data/README.md CHANGED
@@ -30,9 +30,10 @@ result = Komenda.run(['echo', '-n', 'hello'])
30
30
  result.output # => "hello"
31
31
  ```
32
32
 
33
- The `run()` method has a second argument `options`, which expects these keys:
34
- - **`env`** (Hash): The environment variables to use. Defaults to the current process' environment.
35
- - **`cwd`** (String): Directory to change to before running the process. Defaults to `nil`.
33
+ The `run()` method has a second argument `options`, which accepts these optional keys:
34
+ - **`env`** (Hash): Additional environment variables to set.
35
+ - **`reset_bundler_env`** (Boolean): Reset environment variables from your current Ruby bundle using `Bundler.clean_env`. Defaults to `true`.
36
+ - **`cwd`** (String): Directory to change to before running the process.
36
37
 
37
38
  ### Advanced usage
38
39
  The `create()` method creates a `Process` which can be `run()` (or `start()`ed as a Thread).
@@ -76,7 +76,8 @@ module Komenda
76
76
  def run_process(process_builder)
77
77
  opts = {}
78
78
  opts[:chdir] = process_builder.cwd unless process_builder.cwd.nil?
79
- run_popen3(process_builder.env, process_builder.command, opts)
79
+ opts[:unsetenv_others] = true
80
+ run_popen3(process_builder.env_final, process_builder.command, opts)
80
81
  rescue Exception => exception
81
82
  emit(:error, exception)
82
83
  raise exception
@@ -1,7 +1,9 @@
1
1
  module Komenda
2
2
  class ProcessBuilder
3
3
  attr_reader :command
4
+
4
5
  attr_reader :env
6
+ attr_reader :reset_bundler_env
5
7
  attr_reader :cwd
6
8
  attr_reader :events
7
9
 
@@ -9,7 +11,8 @@ module Komenda
9
11
  # @param [Hash] options
10
12
  def initialize(command, options = {})
11
13
  defaults = {
12
- env: ENV.to_hash,
14
+ env: {},
15
+ reset_bundler_env: true,
13
16
  cwd: nil,
14
17
  events: {}
15
18
  }
@@ -17,6 +20,7 @@ module Komenda
17
20
 
18
21
  self.command = command
19
22
  self.env = options[:env]
23
+ self.reset_bundler_env = options[:reset_bundler_env]
20
24
  self.cwd = options[:cwd]
21
25
  self.events = options[:events]
22
26
  end
@@ -40,6 +44,11 @@ module Komenda
40
44
  @env = Hash[env.to_hash.map { |k, v| [String(k), String(v)] }]
41
45
  end
42
46
 
47
+ # @param [Boolean] reset
48
+ def reset_bundler_env=(reset)
49
+ @reset_bundler_env = reset ? true : false
50
+ end
51
+
43
52
  # @param [String] cwd
44
53
  def cwd=(cwd = nil)
45
54
  @cwd = cwd.nil? ? nil : String(cwd)
@@ -49,5 +58,27 @@ module Komenda
49
58
  def events=(events)
50
59
  @events = Hash[events.to_hash.map { |k, v| [k.to_sym, v.to_proc] }]
51
60
  end
61
+
62
+ # @return [Hash]
63
+ def env_final
64
+ if reset_bundler_env && Object.const_defined?('Bundler')
65
+ env_original = bundler_clean_env
66
+ else
67
+ env_original = ENV.to_hash
68
+ end
69
+ env_original.merge(env)
70
+ end
71
+
72
+ private
73
+
74
+ # @return [Hash]
75
+ def bundler_clean_env
76
+ if Bundler.methods(false).include?(:clean_env)
77
+ Bundler.clean_env
78
+ else
79
+ # For Bundler < 1.12.0
80
+ Bundler.with_clean_env { ENV.to_hash }
81
+ end
82
+ end
52
83
  end
53
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: komenda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cargo Media
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-17 00:00:00.000000000 Z
12
+ date: 2016-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: events