shelltastic 0.2.5 → 0.3.0
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.
- data/lib/shelltastic.rb +6 -6
- data/lib/shelltastic/command_io.rb +6 -5
- data/lib/shelltastic/exceptions.rb +1 -1
- data/lib/shelltastic/timer.rb +9 -7
- data/lib/shelltastic/utils.rb +2 -2
- data/lib/shelltastic/version.rb +2 -2
- data/shelltastic.gemspec +4 -4
- data/spec/shelltastic_spec.rb +1 -1
- data/spec/timer_spec.rb +6 -5
- metadata +6 -6
data/lib/shelltastic.rb
CHANGED
@@ -4,20 +4,20 @@ require_relative "shelltastic/command_io"
|
|
4
4
|
require_relative "shelltastic/timer"
|
5
5
|
require_relative "shelltastic/exceptions"
|
6
6
|
|
7
|
-
#
|
7
|
+
# ShellTastic namespace
|
8
8
|
module ShellTastic
|
9
|
-
# Command is the namespace for the actual meat of the gem
|
10
9
|
class Command
|
11
10
|
class << self
|
12
|
-
#
|
11
|
+
# run is the entry point to api
|
13
12
|
# @param command [String] command or multiple commands to be executed
|
13
|
+
# @param command [Array] multiple commands to be executed
|
14
14
|
# @param timer [Object] timer object, @see ShellTastic::Timer
|
15
15
|
# @return [Array] Array of hashes for each command executed @see IO::popen
|
16
16
|
# @example
|
17
|
-
#
|
18
|
-
#
|
17
|
+
# ShellTastic::Command.run "whoami"
|
18
|
+
# ShellTastic::Command.run "whoami", "date"
|
19
19
|
def run(*command)
|
20
|
-
command.flatten.map { |cmd| ShellTastic::IO.popen(cmd, ShellTastic::Timer) }
|
20
|
+
command.flatten.map { |cmd| ShellTastic::IO.popen(cmd, ShellTastic::Timer.new) }
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -8,11 +8,12 @@ module ShellTastic
|
|
8
8
|
class << self
|
9
9
|
# A wrapper around popen4
|
10
10
|
#
|
11
|
-
# @see #
|
12
|
-
# @param command [String] command(s) to
|
13
|
-
# @
|
14
|
-
#
|
15
|
-
|
11
|
+
# @see #run
|
12
|
+
# @param command [String] command(s) to execute
|
13
|
+
# @param command [Array] command(s) to execute
|
14
|
+
# @param command [Time] time object for run time
|
15
|
+
# @return [Array] array of hash meta-data for the command(s) executed
|
16
|
+
def popen(command, timer)
|
16
17
|
string_nil_or_blank?(command)
|
17
18
|
command_results = {}
|
18
19
|
begin
|
data/lib/shelltastic/timer.rb
CHANGED
@@ -1,18 +1,21 @@
|
|
1
1
|
module ShellTastic
|
2
|
-
|
3
|
-
|
2
|
+
class Timer
|
3
|
+
def initialize
|
4
|
+
|
5
|
+
end
|
6
|
+
|
4
7
|
# Creates a start time object
|
5
8
|
# @param [nil]
|
6
9
|
# @return [Time] Time now object
|
7
10
|
def start
|
8
|
-
@
|
11
|
+
@start_time = Time.now
|
9
12
|
end
|
10
13
|
|
11
14
|
# Creates a stop time object
|
12
15
|
# @param [nil]
|
13
16
|
# @return [Time] Time now object
|
14
17
|
def stop
|
15
|
-
@
|
18
|
+
@stop_time = Time.now
|
16
19
|
end
|
17
20
|
|
18
21
|
# Calculates the total time elapsed
|
@@ -22,11 +25,10 @@ module ShellTastic
|
|
22
25
|
# @return [Time] Time elapsed between #start and #stop
|
23
26
|
def total_time(milliseconds = false)
|
24
27
|
if milliseconds
|
25
|
-
(@
|
28
|
+
(@stop_time - @start_time) * 1000.0
|
26
29
|
else
|
27
|
-
@
|
30
|
+
@stop_time - @start_time
|
28
31
|
end
|
29
32
|
end
|
30
33
|
end
|
31
34
|
end
|
32
|
-
end
|
data/lib/shelltastic/utils.rb
CHANGED
@@ -2,12 +2,12 @@ module ShellTastic
|
|
2
2
|
|
3
3
|
module Utils
|
4
4
|
# A dirty string check for nil empty or just whitespace
|
5
|
-
# @param [String]
|
5
|
+
# @param str [String] a string that needs to be checked
|
6
6
|
# @return [Boolean, nil] true if str is empty, nil, or just whitespace
|
7
7
|
def string_nil_or_blank? str
|
8
8
|
# raise if command is empty or nil
|
9
9
|
if str !~ /[^[:space:]]/ || str.nil? || str.empty?
|
10
|
-
raise ShellTastic::CommandException.new("
|
10
|
+
raise ShellTastic::CommandException.new("The command is emtpy or nil")
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
data/lib/shelltastic/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "0.
|
1
|
+
module ShellTastic
|
2
|
+
VERSION = "0.3.0"
|
3
3
|
end
|
data/shelltastic.gemspec
CHANGED
@@ -5,11 +5,11 @@ require 'shelltastic/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "shelltastic"
|
8
|
-
gem.version =
|
9
|
-
gem.authors = ["
|
8
|
+
gem.version = ShellTastic::VERSION
|
9
|
+
gem.authors = ["Bradley Smith"]
|
10
10
|
gem.email = ["bradleydsmith@gmail.com"]
|
11
|
-
gem.description = %q{Shelltastic is
|
12
|
-
gem.summary = %q{*nix shell wrapper}
|
11
|
+
gem.description = %q{Shelltastic is a simple *nix shell wrapper}
|
12
|
+
gem.summary = %q{Shelltastic is a simple *nix shell wrapper}
|
13
13
|
gem.homepage = ""
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
data/spec/shelltastic_spec.rb
CHANGED
data/spec/timer_spec.rb
CHANGED
@@ -2,20 +2,21 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ShellTastic::Timer do
|
4
4
|
it "should report start time" do
|
5
|
-
start = ShellTastic::Timer.start
|
5
|
+
start = ShellTastic::Timer.new.start
|
6
6
|
start.class.should eq(Time)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should report stop time" do
|
10
|
-
stop = ShellTastic::Timer.stop
|
10
|
+
stop = ShellTastic::Timer.new.stop
|
11
11
|
stop.class.should eq(Time)
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should report total time" do
|
15
|
-
|
15
|
+
timer = ShellTastic::Timer.new
|
16
|
+
start = timer.start
|
16
17
|
sleep 2
|
17
|
-
stop =
|
18
|
-
total =
|
18
|
+
stop = timer.stop
|
19
|
+
total = timer.total_time
|
19
20
|
total.round.should eq(2)
|
20
21
|
end
|
21
22
|
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shelltastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
-
|
8
|
+
- Bradley Smith
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
@@ -59,7 +59,7 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
description: Shelltastic is
|
62
|
+
description: Shelltastic is a simple *nix shell wrapper
|
63
63
|
email:
|
64
64
|
- bradleydsmith@gmail.com
|
65
65
|
executables: []
|
@@ -98,7 +98,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
98
|
version: '0'
|
99
99
|
segments:
|
100
100
|
- 0
|
101
|
-
hash:
|
101
|
+
hash: 375658513519469739
|
102
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
103
|
none: false
|
104
104
|
requirements:
|
@@ -107,13 +107,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
segments:
|
109
109
|
- 0
|
110
|
-
hash:
|
110
|
+
hash: 375658513519469739
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project:
|
113
113
|
rubygems_version: 1.8.24
|
114
114
|
signing_key:
|
115
115
|
specification_version: 3
|
116
|
-
summary:
|
116
|
+
summary: Shelltastic is a simple *nix shell wrapper
|
117
117
|
test_files:
|
118
118
|
- spec/shelltastic_spec.rb
|
119
119
|
- spec/spec_helper.rb
|