komenda 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3b17f1984f7f2f3ccab6d25a6ecd9e2714d6710
4
- data.tar.gz: 6d845d8f6974ad2a53d66875e5a0a691459adc1d
3
+ metadata.gz: 9bde725b71b20821b932fda1e83ba82215bfd27d
4
+ data.tar.gz: e682bef86069a8d1d175c9e2d84b14f10c3068ac
5
5
  SHA512:
6
- metadata.gz: 2442eed8d0dcc1acdb1f218e6ac219219dab35bc330d3747ffaf79d3282776a4a282c3e714644cc1f5878e3c5a34cd4fa2ddf1294150e8b30ee5e0decbc8a50a
7
- data.tar.gz: f175f373cd17ff6e84debf25666d1f10584344d886a996059efb3af769345f1f4977bc68c0cffefc44456cb41936dcef5a92b1488e8478d6246b730f198b475a
6
+ metadata.gz: ea96829bf08645726f9cc7727e1531c533a528f6f3b4a8cf3cb75648e206b1b624531b89bab09d34e1df06447fd316702945af386aeda93f47add7b83fbb571e
7
+ data.tar.gz: de7ce00b2c06fa819b2a4b8e3efeaf3cf784e108a78d3b1479db7b3c7aa07f40cbf2599edeb09fecbc7c907c969d0c84d239f88e3e43b7fbaa22ff9a73f6c7dc
data/README.md CHANGED
@@ -22,7 +22,23 @@ result.success? # => true
22
22
  result.pid # => 32157
23
23
  ```
24
24
 
25
+ The `run()` method has a second argument `options`, which expects these keys:
26
+ - **`env`** (Hash): The environment variables to use. Defaults to the current process' environment.
27
+
28
+ Development
29
+ -----------
30
+ Install dependencies:
31
+ ```
32
+ bundle install
33
+ ```
34
+
35
+ Run the tests:
36
+ ```
37
+ bundle exec rake spec
38
+ ```
39
+
25
40
  TODO
26
41
  ----
27
- - `Komenda::Definition`: Allow to pass STDIN
28
- - `Komenda::Definition`: Allow to pass environment variables
42
+ Add options for:
43
+ - Passing STDIN
44
+ - Making `run()` fail when exit status is not "0"
data/lib/komenda.rb CHANGED
@@ -7,9 +7,10 @@ require 'komenda/result'
7
7
  module Komenda
8
8
 
9
9
  # @param [String] cmd
10
+ # @param [Hash] options
10
11
  # @return [Komenda::Result]
11
- def self.run(cmd)
12
- definition = Komenda::Definition.new(cmd)
12
+ def self.run(cmd, options = {})
13
+ definition = Komenda::Definition.new(cmd, options)
13
14
  runner = Komenda::Runner.new
14
15
  runner.run(definition)
15
16
  end
@@ -2,10 +2,18 @@ module Komenda
2
2
  class Definition
3
3
 
4
4
  attr_reader :cmd
5
+ attr_reader :env
5
6
 
6
7
  # @param [String] cmd
7
- def initialize(cmd)
8
- @cmd = cmd
8
+ # @param [Hash] options
9
+ def initialize(cmd, options = {})
10
+ defaults = {
11
+ :env => ENV.to_hash,
12
+ }
13
+ options = defaults.merge(options)
14
+
15
+ @cmd = String(cmd)
16
+ @env = Hash[options[:env].to_hash.map { |k, v| [String(k), String(v)] }]
9
17
  end
10
18
 
11
19
  end
@@ -7,7 +7,7 @@ module Komenda
7
7
  output = {:stdout => '', :stderr => '', :combined => ''}
8
8
  status = nil
9
9
 
10
- Open3.popen3(definition.cmd) do |stdin, stdout, stderr, wait_thr|
10
+ Open3.popen3(definition.env, definition.cmd) do |stdin, stdout, stderr, wait_thr|
11
11
  stdin.close
12
12
 
13
13
  streams_read_open = [stdout, stderr]
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.0.1
4
+ version: 0.0.2
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: 2015-10-27 00:00:00.000000000 Z
12
+ date: 2015-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler