Permalink
Browse files

added README and setup correct backtrace when handling exception

  • Loading branch information...
Ivan Garmatenko
Ivan Garmatenko committed Feb 22, 2012
1 parent d810b0e commit 755c9a3d61e132eca34e628034cffe5ac6fd196a
Showing with 52 additions and 10 deletions.
  1. +38 −0 README.markdown
  2. +9 −1 lib/shell-spinner.rb
  3. +1 −1 lib/shell-spinner/version.rb
  4. +4 −8 shell-spinner.gemspec
View
@@ -0,0 +1,38 @@
+# Shell Spinner
+
+Gem provides animated spinner for UNIX shell and could be used with rake tasks and any console scripts.
+It basically wraps any code and show spinner until code isn't completed.
+
+## Installation
+
+ gem install shell-spinner
+
+## Usage
+
+The main gem function ```ShellSpinner``` accepts text string as first argument,
+which is not required, but it's better to have it for pretty output.
+And it accepts block of code. So spinner will be presented while block is running.
+
+ require 'shell-spinner'
+
+ # With message
+ ShellSpinner "Positive result" do
+ Rake::Task["foo:bar"].invoke
+ end
+
+ # Spinner without message
+ ShellSpinner do
+ sleep 1
+ end
+
+ # With exception
+ ShellSpinner "Code with exception" do
+ sleep 2
+ raise "Some exception"
+ end
+
+This code produces output similar to:
+
+ > Positive result... done
+ > Code with exception... fail
+ > <exception message and backtrace>
View
@@ -19,7 +19,7 @@ def self.with_message text = nil
print "done\n".colorize(:green) unless text.nil?
rescue Exception => e
print "fail\n".colorize(:red) unless text.nil?
- raise e
+ re_raise_exception e
end
end
@@ -37,6 +37,14 @@ def self.join_spinner_thread proc
thread.join
end
+
+ def self.re_raise_exception e
+ raise begin
+ e.class.new(e.message).tap do |exception|
+ exception.set_backtrace e.backtrace
+ end
+ end
+ end
end
def ShellSpinner text = nil, &block
@@ -1,3 +1,3 @@
module ShellSpinner
- VERSION = "0.0.1"
+ VERSION = "1.0.0"
end
View
@@ -7,16 +7,12 @@ Gem::Specification.new do |s|
s.version = ShellSpinner::VERSION
s.authors = ["Ivan Garmatenko"]
s.email = %w(cheef.che@gmail.ru)
- s.homepage = ""
- s.summary = %q{TODO: Write a gem summary}
- s.description = %q{TODO: Write a gem description}
-
- s.rubyforge_project = "shell-spinner"
+ s.homepage = "https://github.com/cheef/shell-spinner"
+ s.summary = %q{Animated spinner for shell}
+ s.description = %q{Gem provides animated spinner for UNIX shell and could be used with rake tasks and any console scripts}
s.files = `git ls-files`.split("\n")
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
- s.require_paths = ["lib"]
+ s.require_paths = %w(lib)
s.add_runtime_dependency "colorize"
end

0 comments on commit 755c9a3

Please sign in to comment.