spit 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.rdoc +11 -3
  2. data/VERSION +1 -1
  3. data/lib/spit.rb +39 -15
  4. data/spit.gemspec +1 -1
  5. metadata +3 -3
data/README.rdoc CHANGED
@@ -2,15 +2,23 @@
2
2
 
3
3
  Spit variables out to your log in a noticeable color. It adds a sensible label automatically.
4
4
 
5
- == Usage Example
5
+ == Usage Examples
6
6
 
7
7
  You use it by doing something like this:
8
8
 
9
9
  Spit account
10
10
 
11
- And it puts something like this in the log output:
11
+ And it puts something like this in the log output (but with color):
12
12
 
13
- *account:* <#Account @name="Steve">
13
+ account: <#Account @name="Steve">
14
+
15
+ To show the source of the line (filename, method, and line number) do something like this:
16
+
17
+ Spit.s account
18
+
19
+ And it puts something like this in the log output (but with color):
20
+
21
+ foo_controller.index(38) account: <#Account @name="Steve">
14
22
 
15
23
  == The Point
16
24
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
data/lib/spit.rb CHANGED
@@ -1,22 +1,46 @@
1
1
  def Spit txt
2
- line = caller[0]
2
+ Spit.print txt, caller[0]
3
+ end
4
+
5
+ module Spit
6
+ def self.s txt
7
+ self.print txt, caller[0], :source=>true
8
+ end
9
+
10
+ def self.print txt, line, options={}
11
+
12
+ txt = txt.inspect rescue txt
13
+
14
+ path, number = line.match(/(.+):(\d+)/)[1..2]
15
+
16
+ label = IO.readlines("/projects/homerun/homerun/app/controllers/web/dev_controller.rb")[number.to_i - 1]
17
+ label.strip!.sub!(/Spit\S+ /, '')
18
+
19
+ label = "#{Spit.extract_label(Spit.parse_line line)} #{label}" if options[:source]
3
20
 
4
- txt = txt.inspect rescue txt
21
+ clear, green, red, yellow, blue, pink, italic, bold, highlight = "\e[0m", "\e[32m", "\e[31m", "\e[33m", "\e[36m", "\e[35m", "\e[3m", "\e[1m", "\e[7m"
22
+ puts "#{green}#{italic}#{label}:#{clear}#{bold}#{yellow} #{txt}#{clear}"
5
23
 
6
- path, number = line.match(/(.+):(\d+)/)[1..2]
24
+ # clear, green, red, yellow, blue, pink, gray, italic, bold = "\e[0m", "\e[32m", "\e[31m", "\e[33m", "\e[36m", "\e[35m", "\e[164m", "\e[3m", "\e[1m"
25
+ # puts "#{red}#{txt}#{clear}"
26
+ # puts "#{green}#{label}:#{clear} #{green}#{highlight}#{txt}#{clear}"
27
+ # puts "#{green}#{label}:#{clear}#{highlight}#{green} #{txt}#{clear}"
28
+ # puts "#{gray}#{txt}:#{clear}#{yellow} #{txt}#{clear}"
29
+ # puts "#{red}#{txt}:#{clear}#{yellow} #{txt}#{clear}"
30
+ # puts "#{red}#{txt} #{clear} aa"
31
+ # puts "#{green}#{label}:#{clear} #{txt}\naaa"
7
32
 
8
- label = IO.readlines("/projects/homerun/homerun/app/controllers/web/dev_controller.rb")[number.to_i - 1]
9
- label.strip!.sub!(/Ol /, '')
33
+ end
10
34
 
11
- clear, green, red, yellow, blue, pink, italic, bold, highlight = "\e[0m", "\e[32m", "\e[31m", "\e[33m", "\e[36m", "\e[35m", "\e[3m", "\e[1m", "\e[7m"
12
- puts "#{green}#{italic}#{label}:#{clear}#{bold}#{yellow} #{txt}#{clear}"
35
+ def self.parse_line path
36
+ method = path[/`(.+)'/, 1] # `
37
+ path, l = path.match(/(.+):(\d+)/)[1..2]
38
+ path = File.expand_path path
39
+ clazz = path[/.+\/(.+)\.rb/, 1]
40
+ {:path=>path, :line=>l, :method=>method, :clazz=>clazz}
41
+ end
13
42
 
14
- # clear, green, red, yellow, blue, pink, gray, italic, bold = "\e[0m", "\e[32m", "\e[31m", "\e[33m", "\e[36m", "\e[35m", "\e[164m", "\e[3m", "\e[1m"
15
- # puts "#{red}#{txt}#{clear}"
16
- # puts "#{green}#{label}:#{clear} #{green}#{highlight}#{txt}#{clear}"
17
- # puts "#{green}#{label}:#{clear}#{highlight}#{green} #{txt}#{clear}"
18
- # puts "#{gray}#{txt}:#{clear}#{yellow} #{txt}#{clear}"
19
- # puts "#{red}#{txt}:#{clear}#{yellow} #{txt}#{clear}"
20
- # puts "#{red}#{txt} #{clear} aa"
21
- # puts "#{green}#{label}:#{clear} #{txt}\naaa"
43
+ def self.extract_label h
44
+ "#{h[:clazz]}.#{h[:method]}(#{h[:line]})"
45
+ end
22
46
  end
data/spit.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{spit}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["trogdoro"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - trogdoro