lll 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/.gitignore +1 -2
  2. data/VERSION +1 -1
  3. data/lib/lll.rb +29 -24
  4. data/lll.gemspec +108 -0
  5. metadata +4 -3
data/.gitignore CHANGED
@@ -1,7 +1,6 @@
1
+ instructions
1
2
  *.sw?
2
3
  .DS_Store
3
4
  coverage
4
5
  rdoc
5
6
  pkg
6
- .idea
7
- *.gemspec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.3.0
data/lib/lll.rb CHANGED
@@ -6,33 +6,38 @@
6
6
  # Enumerable members are output on separate lines
7
7
 
8
8
  def lll msg = nil, &block
9
- s = " "
10
- expression_string = ''
11
- expression_value = 0
12
- if block_given?
13
- s << msg + ': ' if msg
14
- expression_string = block.call
15
- expression_value = eval(expression_string, block)
16
- s << expression_string + ' = '
17
- if expression_value.respond_to?(:each) && !expression_value.is_a?(String) && !expression_value.is_a?(Nokogiri::HTML::Document)
18
- s << " \n"
19
- expression_value.each { |e| s << ' ' << e.inspect << " \n" }
9
+ Lll.lll msg, block
10
+ end
11
+
12
+ module Lll
13
+ def self.lll msg, block = nil
14
+ output_string = " "
15
+ expression_value = 0
16
+ if block
17
+ output_string << msg + ': ' if msg
18
+ expression_string = block.call
19
+ expression_value = eval(expression_string, block)
20
+ output_string << expression_string + ' = '
21
+ if expression_value.respond_to?(:each) && !expression_value.is_a?(String) && !expression_value.is_a?(Nokogiri::HTML::Document)
22
+ output_string << " \n"
23
+ expression_value.each { |e| output_string << ' ' << e.inspect << " \n" }
24
+ else
25
+ output_string << expression_value.inspect << " \n"
26
+ end
20
27
  else
21
- s << expression_value.inspect << " \n"
28
+ output_string << msg if msg
29
+ output_string << " \n"
22
30
  end
23
- else
24
- s << msg if msg
25
- s << " \n"
26
- end
27
31
 
28
- reverse_video_color_code = "\e[7m"
29
- reset_color_code = "\e[0m"
30
-
31
- s = reverse_video_color_code + s + reset_color_code
32
- s << 'lll: ' + caller.first.to_s + ' ' + Time.now.strftime('%X')
32
+ Kernel.puts format(output_string, ENV['TERM'] != 'dumb')
33
+ Rails.logger.debug(format(output_string)) if defined?(Rails) && Rails.logger
33
34
 
34
- Kernel.puts s
35
- Rails.logger.debug s if defined?(Rails) && Rails.logger
35
+ expression_value
36
+ end
36
37
 
37
- expression_value
38
+ def self.format output_string, colorize = true
39
+ string = output_string
40
+ string = "\e[7m" + string + "\e[0m" if colorize
41
+ string + "lll: #{caller[2].to_s} #{Time.now.strftime('%X')}"
42
+ end
38
43
  end
data/lll.gemspec ADDED
@@ -0,0 +1,108 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{lll}
8
+ s.version = "1.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Mark Wilden"]
12
+ s.date = %q{2010-11-26}
13
+ s.description = %q{= lll
14
+
15
+ lll() is used in debugging to display an expression and its value.
16
+
17
+ === Motivation
18
+
19
+ One of the most basic tools in debugging is printing out the values of
20
+ variables (or other expressions) during program execution:
21
+
22
+ puts user_name
23
+
24
+ Sometimes you need to label these values so you know what they're
25
+ referring to, especially if you're outputting a lot of them:
26
+
27
+ puts "user_name = #{message}"
28
+
29
+ lll() does the labelling automatically:
30
+
31
+ lll{'user_name'}
32
+
33
+ The expression is passed as a string inside a block. It's useful to
34
+ create a text editor macro that outputs <tt>lll{''}</tt> and leaves the
35
+ cursor inside the apostrophes.
36
+
37
+ === Other benefits
38
+
39
+ Output goes to standard output and the Rails log (if available).
40
+
41
+ Output is displayed in reverse video, so it's easy to pick out from the
42
+ log or console.
43
+
44
+ lll() uses #inspect to output the expression. It outputs Enumerable
45
+ members (except strings) on separate lines.
46
+
47
+ Output is tagged with the file and line number where it appears, so
48
+ you can easily find lll's that you forgot to take out. The time of
49
+ day (but not the date) is also printed, so you don't waste time
50
+ looking at old output.
51
+
52
+ === Outputting additional text
53
+
54
+ Sometimes you want to include some other string, along with the label
55
+ and value like this:
56
+
57
+ puts "After polling the queue, user_name = #{user_name}"
58
+
59
+ You can pass a string to lll() to print a string:
60
+
61
+ lll("After polling the queue"){'user_name'}
62
+
63
+ And because lll() outputs in reverse video, and to the Rails log, it can
64
+ be useful to simply print a string without an expression:
65
+
66
+ lll "After read_user"
67
+
68
+ === Copyright
69
+
70
+ Copyright (c) 2009 Mark Wilden. See LICENSE for details.
71
+ }
72
+ s.email = %q{mark@mwilden.com}
73
+ s.extra_rdoc_files = [
74
+ "LICENSE",
75
+ "README.rdoc"
76
+ ]
77
+ s.files = [
78
+ ".document",
79
+ ".gitignore",
80
+ "LICENSE",
81
+ "README.rdoc",
82
+ "Rakefile",
83
+ "VERSION",
84
+ "doc/README_rdoc.html",
85
+ "lib/lll.rb",
86
+ "lll.gemspec",
87
+ "test/test.rb"
88
+ ]
89
+ s.homepage = %q{http://github.com/mwilden/lll}
90
+ s.rdoc_options = ["--charset=UTF-8"]
91
+ s.require_paths = ["lib"]
92
+ s.rubygems_version = %q{1.3.6}
93
+ s.summary = %q{Output labeled data when debugging}
94
+ s.test_files = [
95
+ "test/test.rb"
96
+ ]
97
+
98
+ if s.respond_to? :specification_version then
99
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
100
+ s.specification_version = 3
101
+
102
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
103
+ else
104
+ end
105
+ else
106
+ end
107
+ end
108
+
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 1.2.0
9
+ version: 1.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mark Wilden
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-11 00:00:00 -07:00
17
+ date: 2010-11-26 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -95,6 +95,7 @@ files:
95
95
  - VERSION
96
96
  - doc/README_rdoc.html
97
97
  - lib/lll.rb
98
+ - lll.gemspec
98
99
  - test/test.rb
99
100
  has_rdoc: true
100
101
  homepage: http://github.com/mwilden/lll