tell_me_about_it 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/lib/tell_me_about_it/version.rb +3 -0
- data/lib/tell_me_about_it.rb +245 -0
- data/tell_me_about_it.gemspec +25 -0
- metadata +87 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2@tell_me_about_it --create
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,245 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'benchmark'
|
3
|
+
require 'colorful'
|
4
|
+
require 'tell_me_about_it/version'
|
5
|
+
|
6
|
+
module TellMeAboutIt
|
7
|
+
COLORS = { :count => '00a0b0',
|
8
|
+
:file => '666',
|
9
|
+
:context => '999',
|
10
|
+
:self => '793A57',
|
11
|
+
:method => 'fff',
|
12
|
+
:args => 'EB6841',
|
13
|
+
:result => '2DE04D',
|
14
|
+
:time_good => 'EDC951',
|
15
|
+
:time_bad => 'CC333F' }
|
16
|
+
|
17
|
+
def self.reset
|
18
|
+
$_tma_count = 0
|
19
|
+
$_tma_indent = 0
|
20
|
+
$_tma_last_indent = 0
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.inc
|
24
|
+
$_tma_count += 1
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.indent
|
28
|
+
$_tma_indent += 1
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.outdent
|
32
|
+
$_tma_indent -= 1
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.remember_indent
|
36
|
+
$_tma_last_indent = $_tma_indent
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.count
|
40
|
+
$_tma_count ||= 0
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.indent_level
|
44
|
+
$_tma_indent ||= 0
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.indent_changed?
|
48
|
+
$_tma_indent < $_tma_last_indent
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.count_str
|
52
|
+
" ##{count.to_s} ".color(COLORS[:count]).bold
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.self_str passed_self
|
56
|
+
passed_self.inspect.color(COLORS[:self])
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.file_str method_caller
|
60
|
+
file_name, line_number = method_caller[0].split(':', 3)
|
61
|
+
"#{file_name}:#{line_number}".color(COLORS[:file])
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.context_str method_caller
|
65
|
+
file_name, line_number, context = method_caller[0].split(':', 3)
|
66
|
+
begin
|
67
|
+
actual_line = File.readlines(file_name)[line_number.to_i - 1].strip
|
68
|
+
rescue Exception => e
|
69
|
+
actual_line = "Unable to open #{file_name}:#{line_number}"
|
70
|
+
end
|
71
|
+
"#{context} ... #{actual_line}".color(COLORS[:context])
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.method_str method_name, *args
|
75
|
+
name_str = "#{method_name}".bold
|
76
|
+
args_str = "(#{args.map(&:inspect).map {|a| a.color(COLORS[:args])}.join(', ')})"
|
77
|
+
name_str + args_str
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.indent_str
|
81
|
+
indent_level.times.inject('') {|m| m += " │ "}
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.start_indent_str
|
85
|
+
indent_str.reverse.sub(" │", "─├").reverse + "─┬─"
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.cont_indent_str
|
89
|
+
"#{indent_str} │ "
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.end_indent_str
|
93
|
+
"#{indent_str} └─"
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.time_str seconds
|
97
|
+
time_str = (' ' * count.to_s.size) + ("%.4f sec" % seconds)
|
98
|
+
seconds > 0.05 ? time_str.color(COLORS[:time_bad]) : time_str.color(COLORS[:time_good])
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.result_str result
|
102
|
+
result.inspect.color(COLORS[:result])
|
103
|
+
end
|
104
|
+
|
105
|
+
def tell_me_about(*method_names)
|
106
|
+
method_names.each do |method_name|
|
107
|
+
if class_method? method_name
|
108
|
+
tell_me_about_class_method method_name
|
109
|
+
else
|
110
|
+
tell_me_about_instance_method method_name
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def tell_me_about_class_method(*method_names)
|
116
|
+
method_names.each do |method_name|
|
117
|
+
class_eval <<-EOS, __FILE__, __LINE__ + 1
|
118
|
+
class << self
|
119
|
+
#{make_talk method_name}
|
120
|
+
end
|
121
|
+
EOS
|
122
|
+
end
|
123
|
+
end
|
124
|
+
alias tell_me_about_class_methods tell_me_about_class_method
|
125
|
+
|
126
|
+
def tell_me_about_instance_method(*method_names)
|
127
|
+
method_names.each do |method_name|
|
128
|
+
class_eval <<-EOS, __FILE__, __LINE__ + 1
|
129
|
+
#{make_talk method_name}
|
130
|
+
EOS
|
131
|
+
end
|
132
|
+
end
|
133
|
+
alias tell_me_about_instance_methods tell_me_about_instance_method
|
134
|
+
|
135
|
+
private
|
136
|
+
|
137
|
+
def class_method? method_name
|
138
|
+
class_eval { respond_to? method_name }
|
139
|
+
end
|
140
|
+
|
141
|
+
def make_talk method_name
|
142
|
+
original_method = "_quiet_#{method_name}"
|
143
|
+
<<-EOF
|
144
|
+
if method_defined?(:#{original_method})
|
145
|
+
return
|
146
|
+
end
|
147
|
+
alias #{original_method} #{method_name}
|
148
|
+
|
149
|
+
def #{method_name}(*args, &blk)
|
150
|
+
TellMeAboutIt.inc
|
151
|
+
|
152
|
+
count_str = TellMeAboutIt.count_str
|
153
|
+
|
154
|
+
indent_str = TellMeAboutIt.indent_str
|
155
|
+
start_indent_str = TellMeAboutIt.start_indent_str
|
156
|
+
cont_indent_str = TellMeAboutIt.cont_indent_str
|
157
|
+
end_indent_str = TellMeAboutIt.end_indent_str
|
158
|
+
|
159
|
+
method_str = TellMeAboutIt.method_str :#{method_name}, *args
|
160
|
+
file_str = TellMeAboutIt.file_str(caller)
|
161
|
+
context_str = TellMeAboutIt.context_str(caller)
|
162
|
+
self_str = TellMeAboutIt.self_str(self)
|
163
|
+
|
164
|
+
if defined?(Rails)
|
165
|
+
file_str.sub!(Rails.root.to_s, '')
|
166
|
+
end
|
167
|
+
|
168
|
+
puts indent_str
|
169
|
+
puts start_indent_str + count_str + self_str + "." + method_str
|
170
|
+
puts "\#{cont_indent_str} \#{file_str}"
|
171
|
+
puts "\#{cont_indent_str} \#{context_str}"
|
172
|
+
|
173
|
+
TellMeAboutIt.indent
|
174
|
+
result = nil
|
175
|
+
seconds = Benchmark.realtime { result = #{original_method}(*args, &blk) }
|
176
|
+
time_str = TellMeAboutIt.time_str(seconds)
|
177
|
+
result_str = TellMeAboutIt.result_str(result)
|
178
|
+
TellMeAboutIt.outdent
|
179
|
+
|
180
|
+
puts cont_indent_str if TellMeAboutIt.indent_changed?
|
181
|
+
puts end_indent_str + count_str + self_str + "." + method_str + " ⊢ " + result_str
|
182
|
+
|
183
|
+
TellMeAboutIt.remember_indent
|
184
|
+
|
185
|
+
puts indent_str + " " + time_str
|
186
|
+
|
187
|
+
result
|
188
|
+
end
|
189
|
+
EOF
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
TellMeAboutIt.reset
|
195
|
+
|
196
|
+
class Object
|
197
|
+
extend TellMeAboutIt
|
198
|
+
end
|
199
|
+
|
200
|
+
class Fib
|
201
|
+
def no_args
|
202
|
+
5
|
203
|
+
end
|
204
|
+
|
205
|
+
def fib x
|
206
|
+
return 1 if x <= 2
|
207
|
+
fib(x - 1) + fib(x - 2)
|
208
|
+
end
|
209
|
+
|
210
|
+
def self.find x
|
211
|
+
return 1 if x <= 2
|
212
|
+
find(x - 1) + find(x - 2)
|
213
|
+
end
|
214
|
+
|
215
|
+
def find x
|
216
|
+
x * 2
|
217
|
+
end
|
218
|
+
|
219
|
+
def fib_block &blk
|
220
|
+
fib yield
|
221
|
+
end
|
222
|
+
tell_me_about :fib_block
|
223
|
+
|
224
|
+
def mergesort(list)
|
225
|
+
return list if list.size <= 1
|
226
|
+
mid = list.size / 2
|
227
|
+
left = list[0, mid]
|
228
|
+
right = list[mid, list.size]
|
229
|
+
merge(mergesort(left), mergesort(right))
|
230
|
+
end
|
231
|
+
tell_me_about :mergesort
|
232
|
+
|
233
|
+
def merge(left, right)
|
234
|
+
sorted = []
|
235
|
+
until left.empty? or right.empty?
|
236
|
+
if left.first <= right.first
|
237
|
+
sorted << left.shift
|
238
|
+
else
|
239
|
+
sorted << right.shift
|
240
|
+
end
|
241
|
+
end
|
242
|
+
sorted.concat(left).concat(right)
|
243
|
+
end
|
244
|
+
tell_me_about :merge
|
245
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "tell_me_about_it/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "tell_me_about_it"
|
7
|
+
s.version = TellMeAboutIt::VERSION
|
8
|
+
s.authors = ["Nick Karpenske"]
|
9
|
+
s.email = ["randland@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Terminal Color Manager}
|
12
|
+
s.description = %q{Provides a simple interface for terminal output colors and effects}
|
13
|
+
|
14
|
+
s.rubyforge_project = "tell_me_about_it"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
s.add_development_dependency "fuubar"
|
24
|
+
s.add_runtime_dependency "colorful"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tell_me_about_it
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nick Karpenske
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-14 00:00:00.000000000 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
requirement: &2153383400 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2153383400
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: fuubar
|
28
|
+
requirement: &2153382980 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *2153382980
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: colorful
|
39
|
+
requirement: &2153382560 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *2153382560
|
48
|
+
description: Provides a simple interface for terminal output colors and effects
|
49
|
+
email:
|
50
|
+
- randland@gmail.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- .rvmrc
|
57
|
+
- Gemfile
|
58
|
+
- Rakefile
|
59
|
+
- lib/tell_me_about_it.rb
|
60
|
+
- lib/tell_me_about_it/version.rb
|
61
|
+
- tell_me_about_it.gemspec
|
62
|
+
has_rdoc: true
|
63
|
+
homepage: ''
|
64
|
+
licenses: []
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project: tell_me_about_it
|
83
|
+
rubygems_version: 1.6.2
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Terminal Color Manager
|
87
|
+
test_files: []
|