komenda 0.1.6 → 0.1.7

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: 5776b8baf0623308ba5d91c4af70d4de9e6a63c6
4
- data.tar.gz: de78e64e458c3d8efe96cecbb630c7e5fb6274b7
3
+ metadata.gz: 539e892cf6dd52f871008d73d4597f549c40664a
4
+ data.tar.gz: 6421357e13b63bb9e3c59f45532cd72b8e4ea4db
5
5
  SHA512:
6
- metadata.gz: 1644ff0df3f0e8954c6e9b81a736ae37763dc4a8efd0dd78bcab82d43048020d409a44a2fdbb2e131376224465e441b2122efdd040c5b314bfe7f158b5b0d206
7
- data.tar.gz: 82d702d169daebb599300567684df3272d8c5aa3cd3fcbdf0e1cee2fec22aff15a1a7ccca596a82801a3196e9d9f712942bffbcc4f0703fa8d080a5ad2069a40
6
+ metadata.gz: b9c596b3f1c0cf1c50630ca6044793f85be884fb78367b1250840d7f90626cef45a1610d1044cddcabfb3a47089720bac0dc792a7ba4787df0d2d58dcf47685d
7
+ data.tar.gz: 5d0bd13566dfc652623f33240611830c1cf0fa205ba355e8ac98af28c4530d64c494db093201b5b94792065d11ae76faa4340b19c0fc59e699b202391753ffb9
data/README.md CHANGED
@@ -25,18 +25,25 @@ result.success? # => true
25
25
  result.pid # => 32157
26
26
  ```
27
27
  The program and its arguments can be passed as an array:
28
- ```ruby
28
+ ```ruby
29
29
  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 accepts these optional keys:
33
+ ### Run options
34
+ The `run()` method has a second argument `options`.
35
+ ```ruby
36
+ result = Komenda.run('date', fail_on_fail: true)
37
+ ```
38
+
39
+
40
+ The following options can be configured:
34
41
  - **`env`** (Hash): Additional environment variables to set.
35
- - **`use_bundler_env`** (Boolean): Use the environment variable of the current [bundle](http://bundler.io/). Defaults to `false`.
42
+ - **`use_bundler_env`** (Boolean): Use the [environment of the current bundle](http://www.cargomedia.ch/2016/03/18/reset-bundler-environment.html). Defaults to `false`.
36
43
  - **`cwd`** (String): Directory to change to before running the process.
37
44
  - **`fail_on_fail`** (Boolean): Whether to raise an error when the exit code is not "0". Defaults to `false`.
38
45
 
39
- ### Advanced usage
46
+ ### Asynchronous running
40
47
  The `create()` method creates a `Process` which can be `run()` (or `start()`ed as a Thread).
41
48
  ```
42
49
  process = Komenda.create('date')
@@ -67,9 +74,3 @@ Run the tests:
67
74
  ```
68
75
  bundle exec rake spec
69
76
  ```
70
-
71
- TODO
72
- ----
73
- Add options for:
74
- - Passing STDIN
75
- - Making `run()` fail when exit status is not '0'
@@ -20,16 +20,16 @@ module Komenda
20
20
 
21
21
  # @return [Thread]
22
22
  def start
23
- fail 'Already started' if started?
23
+ raise 'Already started' if started?
24
24
  @thread = Thread.new { run_process(@process_builder) }
25
25
  end
26
26
 
27
27
  # @return [Komenda::Result]
28
28
  def wait_for
29
- fail 'Process not started' unless started?
29
+ raise 'Process not started' unless started?
30
30
  @thread.join
31
31
  if @process_builder.fail_on_fail && !result.success?
32
- fail "Process failed with exit status `#{result.exitstatus}` and output:\n#{result.output}"
32
+ raise "Process failed with exit status `#{result.exitstatus}` and output:\n#{result.output}"
33
33
  end
34
34
  result
35
35
  end
@@ -42,7 +42,7 @@ module Komenda
42
42
 
43
43
  # @return [Integer]
44
44
  def pid
45
- fail 'No PID available' if @pid.nil?
45
+ raise 'No PID available' if @pid.nil?
46
46
  @pid
47
47
  end
48
48
 
@@ -58,8 +58,8 @@ module Komenda
58
58
 
59
59
  # @return [Komenda::Result]
60
60
  def result
61
- fail 'Process not started' unless started?
62
- fail 'Process not finished' unless finished?
61
+ raise 'Process not started' unless started?
62
+ raise 'Process not finished' unless finished?
63
63
  Komenda::Result.new(@output, @exit_status)
64
64
  end
65
65
 
@@ -35,11 +35,11 @@ module Komenda
35
35
 
36
36
  # @param [String, Array<String>] command
37
37
  def command=(command)
38
- if command.is_a?(Array)
39
- @command = command.map { |v| String(v) }
40
- else
41
- @command = String(command)
42
- end
38
+ @command = if command.is_a?(Array)
39
+ command.map { |v| String(v) }
40
+ else
41
+ String(command)
42
+ end
43
43
  end
44
44
 
45
45
  # @param [Hash] env
@@ -69,11 +69,11 @@ module Komenda
69
69
 
70
70
  # @return [Hash]
71
71
  def env_final
72
- if !use_bundler_env && Object.const_defined?('Bundler')
73
- env_original = bundler_clean_env
74
- else
75
- env_original = ENV.to_hash
76
- end
72
+ env_original = if !use_bundler_env && Object.const_defined?('Bundler')
73
+ bundler_clean_env
74
+ else
75
+ ENV.to_hash
76
+ end
77
77
  env_original.merge(env)
78
78
  end
79
79
 
@@ -25,7 +25,7 @@ module Komenda
25
25
  @status.exitstatus
26
26
  end
27
27
 
28
- alias_method :status, :exitstatus
28
+ alias status exitstatus
29
29
 
30
30
  def success?
31
31
  exitstatus == 0
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.6
4
+ version: 0.1.7
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-04-24 00:00:00.000000000 Z
12
+ date: 2016-10-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: events
@@ -87,14 +87,14 @@ dependencies:
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: 0.35.0
90
+ version: 0.41.2
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: 0.35.0
97
+ version: 0.41.2
98
98
  description: Convenience wrapper around `Open3` to run shell commands in Ruby.
99
99
  email: hello@cargomedia.ch
100
100
  executables: []
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  requirements: []
129
129
  rubyforge_project:
130
- rubygems_version: 2.6.2
130
+ rubygems_version: 2.5.1
131
131
  signing_key:
132
132
  specification_version: 4
133
133
  summary: Convenience wrapper around `Open3` to run shell commands in Ruby.