Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ae043be
Showing
11 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--color --format d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
rvm --install ruby-1.9.2-p180 | ||
rvm --create --install use ruby-1.9.2-p180@command_line_reporter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
source 'http://rubygems.org' | ||
|
||
gem 'rspec', '>=2.4' | ||
gem 'ruby-debug19' | ||
gem 'autotest' | ||
gem 'autotest-growl' | ||
gem 'rake' | ||
gem 'kramdown' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
ZenTest (4.6.2) | ||
archive-tar-minitar (0.5.2) | ||
autotest (4.4.6) | ||
ZenTest (>= 4.4.1) | ||
autotest-growl (0.2.16) | ||
columnize (0.3.4) | ||
diff-lcs (1.1.3) | ||
kramdown (0.13.3) | ||
linecache19 (0.5.12) | ||
ruby_core_source (>= 0.1.4) | ||
rake (0.9.2.2) | ||
rspec (2.7.0) | ||
rspec-core (~> 2.7.0) | ||
rspec-expectations (~> 2.7.0) | ||
rspec-mocks (~> 2.7.0) | ||
rspec-core (2.7.1) | ||
rspec-expectations (2.7.0) | ||
diff-lcs (~> 1.1.2) | ||
rspec-mocks (2.7.0) | ||
ruby-debug-base19 (0.11.25) | ||
columnize (>= 0.3.1) | ||
linecache19 (>= 0.5.11) | ||
ruby_core_source (>= 0.1.4) | ||
ruby-debug19 (0.11.6) | ||
columnize (>= 0.3.1) | ||
linecache19 (>= 0.5.11) | ||
ruby-debug-base19 (>= 0.11.19) | ||
ruby_core_source (0.1.5) | ||
archive-tar-minitar (>= 0.5.2) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
autotest | ||
autotest-growl | ||
kramdown | ||
rake | ||
rspec (>= 2.4) | ||
ruby-debug19 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'bundler' | ||
Bundler::GemHelper.install_tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
$: << File.join(__FILE__, '..', 'lib') | ||
|
||
require 'date' | ||
require 'command_line_reporter/version' | ||
|
||
Gem::Specification.new do |gem| | ||
gem.name = 'command_line_reporter' | ||
gem.version = command_line_reporter::VERSION | ||
gem.date = Date.today.to_s | ||
|
||
gem.summary = 'A tool for providing interactive command line applications' | ||
gem.description = 'This gem makes it easy to provide a report while your ruby script is executing' | ||
|
||
gem.authors = %w/Wes Bailey/ | ||
gem.email = 'baywes@gmail.com' | ||
gem.homepage = 'http://github.com/wbailey/command_line_reporter' | ||
|
||
gem.files = Dir['lib/**/*', 'README*', 'LICENSE*'] & `git ls-files -z`.split("\0") | ||
gem.test_files = Dir['spec/**/*'] & `git ls-files -z`.split("\0") | ||
|
||
gem.add_development_dependency "bundler", ">= 1.0.0" | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'command_line_reporter' | ||
|
||
class Example | ||
include CommandLineReporter | ||
|
||
def initialize | ||
self.clr_complete_string = 'done' | ||
end | ||
|
||
def run | ||
x,y,z = 0,0,0 | ||
|
||
report(:message => 'calculating first expression') do | ||
x = 2 + 2 | ||
sleep 1 | ||
|
||
2.times do | ||
report(:message => 'calculating second expression') do | ||
y = 10 - x | ||
sleep 1 | ||
|
||
10.times do |i| | ||
report(:message => 'pixelizing', :type => 'inline', :complete => "#{i*10}%") do | ||
z = x + y | ||
sleep 1 | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
puts '-' * 20 | ||
%w(x y z).each {|v| puts "#{v}: #{eval v}"} | ||
end | ||
end | ||
|
||
Example.new.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module CommandLineReporter | ||
attr_accessor :command_line_reporter_indent, :command_line_reporter_complete_string, :command_line_reporter_indent_size | ||
|
||
def report(options = {}) | ||
raise ArgumentError unless (options.keys - [:message, :type, :complete, :indent_size]).empty? | ||
|
||
self.command_line_reporter_indent = (self.command_line_reporter_indent) ? self.command_line_reporter_indent += 1 : 0 | ||
|
||
padding = ' ' * self.command_line_reporter_indent * (options[:indent_size] || self.command_line_reporter_indent_size) | ||
|
||
start_str = "#{padding}#{options[:message]}" | ||
end_str = options[:complete] || self.command_line_reporter_complete_string | ||
|
||
if options[:type] == 'inline' | ||
print "#{start_str}..." | ||
else | ||
puts start_str | ||
end_str = padding + end_str | ||
end | ||
|
||
yield | ||
|
||
puts end_str | ||
|
||
self.command_line_reporter_indent -= 1 | ||
end | ||
|
||
def command_line_reporter_complete_string | ||
@command_line_reporter_complete_string ||= 'complete' | ||
end | ||
|
||
def command_line_reporter_indent_size | ||
@command_line_reporter_indent_size ||= 2 | ||
end | ||
end | ||
|
||
class Example | ||
attr_accessor :expresssions | ||
|
||
include CommandLineReporter | ||
|
||
def initialize | ||
self.command_line_reporter_complete_string = 'done' | ||
end | ||
|
||
def run | ||
x,y,z = 0,0,0 | ||
|
||
report(:message => 'calculating first expression') do | ||
x = 2 + 2 | ||
sleep 1 | ||
|
||
2.times do | ||
report(:message => 'calculating second expression') do | ||
y = 10 - x | ||
sleep 1 | ||
|
||
10.times do |i| | ||
report(:message => 'pixelizing', :type => 'inline', :complete => "#{i*10}%") do | ||
z = x + y | ||
sleep 1 | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
puts '-' * 20 | ||
%w(x y z).each {|v| puts "#{v}: #{eval v}"} | ||
end | ||
end | ||
|
||
Example.new.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module command_line_reporter | ||
VERSION = '0.1.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
$: << File.join(File.dirname(__FILE__), '..', 'lib') | ||
require 'command_line_reporter' | ||
|
||
describe CommandLineReporter do | ||
let :use_class do | ||
Class.new do | ||
include CommandLineReporter | ||
end | ||
end | ||
|
||
subject { use_class.new } | ||
|
||
describe "#report" do | ||
context 'argument validation' do | ||
it 'raises exception when there is an invalid argument' do | ||
lambda { | ||
subject.report(:asdf => true) | ||
}.should raise_exception /ArgumentError/ | ||
end | ||
|
||
it 'raises an exception when a block is not given' do | ||
lambda { | ||
subject.report(:message => 'test') | ||
}.should raise_exception /ArgumentError/ | ||
end | ||
|
||
it 'accepts valid arguments' do | ||
subject.should_receive(:puts).with('test') | ||
subject.should_receive(:puts).with('complete') | ||
|
||
lambda { | ||
subject.report(:message => 'test') do | ||
end | ||
}.should_not raise_exception | ||
end | ||
end | ||
end | ||
|
||
describe 'default values' do | ||
its(:clr_complete_string) { should eq 'complete' } | ||
its(:clr_indent_size) { should eq 2 } | ||
end | ||
end |