quicklog 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/lib/quicklog/version.rb +1 -1
- data/lib/quicklog.rb +16 -5
- data/test/test_quicklog.rb +19 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ea4068192d43208f2ce33811d13cd5e64508a1e
|
4
|
+
data.tar.gz: 1a6abfbbc853782ef0b782986e53280f138bae8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 116a0a6ff6cd19bf55a943df7f8524c4520155e1f32dd7db6b1bee01a83f917af42fb15f3a2bed93ec262b4b9b071c5b604e774fdfa8eb35735f715b9c43bdeb
|
7
|
+
data.tar.gz: 8547105271de1c65c1f9f2a609a1fb7937cd7a352552b2a17075daca55b160c17891c78a51ab750b34d6c7299218f73ec590c3bca3b7af852d6c98fef358a2a5
|
data/README.md
CHANGED
@@ -12,9 +12,15 @@ write
|
|
12
12
|
|
13
13
|
For Ruby 2+ only.
|
14
14
|
|
15
|
+
## Additional features
|
16
|
+
|
17
|
+
* display output in reverse video, it's easier to see
|
18
|
+
* not limited to variable logging, can log anything that can be converted to a string
|
19
|
+
|
15
20
|
## Examples
|
16
21
|
|
17
22
|
* logging an object attribute: `ql :"@user.name"`
|
23
|
+
* logging a plain string: `ql "hello world!"`
|
18
24
|
|
19
25
|
## Installation
|
20
26
|
|
@@ -46,8 +52,6 @@ I found the solution I needed in this [stackoverflow answer](http://stackoverflo
|
|
46
52
|
|
47
53
|
## TODO
|
48
54
|
|
49
|
-
* display in reverse video
|
50
|
-
* allow logging of strings, ie `ql "hi!"`
|
51
55
|
* use inspect to output the expression
|
52
56
|
* use Awesome Print if available
|
53
57
|
* allow logging of string + variable: `ql "hi!", :my_var`
|
data/lib/quicklog/version.rb
CHANGED
data/lib/quicklog.rb
CHANGED
@@ -2,17 +2,28 @@ require "quicklog/version"
|
|
2
2
|
require 'debug_inspector'
|
3
3
|
|
4
4
|
module Quicklog
|
5
|
-
def self.ql
|
5
|
+
def self.ql param
|
6
|
+
output = param.is_a?(Symbol) ? label_and_value_as_string(param) : String(param)
|
7
|
+
puts reverse_video output
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def self.label_and_value_as_string symbol
|
6
13
|
RubyVM::DebugInspector.open do |inspector|
|
7
|
-
value = eval
|
8
|
-
|
14
|
+
value = eval symbol.to_s, inspector.frame_binding(4)
|
15
|
+
"#{symbol} = #{value}"
|
9
16
|
end
|
10
17
|
end
|
18
|
+
|
19
|
+
def self.reverse_video string
|
20
|
+
"\e[7m" + string + "\e[0m"
|
21
|
+
end
|
11
22
|
end
|
12
23
|
|
13
24
|
module Kernel
|
14
|
-
def ql
|
15
|
-
Quicklog.ql
|
25
|
+
def ql param
|
26
|
+
Quicklog.ql param
|
16
27
|
end
|
17
28
|
module_function :ql
|
18
29
|
end
|
data/test/test_quicklog.rb
CHANGED
@@ -2,16 +2,32 @@ require "minitest/autorun"
|
|
2
2
|
require "mocha/setup"
|
3
3
|
require "quicklog"
|
4
4
|
|
5
|
+
def in_reverse_video string
|
6
|
+
"\e[7m" + string + "\e[0m"
|
7
|
+
end
|
8
|
+
|
5
9
|
class QuicklogTest < Minitest::Test
|
6
|
-
|
10
|
+
|
11
|
+
def test_log_variable_label_and_value_in_reverse_video
|
7
12
|
my_var = 2
|
8
|
-
$stdout.expects(:puts).with("my_var = 2")
|
13
|
+
$stdout.expects(:puts).with(in_reverse_video "my_var = 2")
|
9
14
|
ql :my_var
|
10
15
|
end
|
11
16
|
|
12
17
|
def test_log_object_attribute
|
13
18
|
person = Struct.new(:name).new "David"
|
14
|
-
$stdout.expects(:puts).with("person.name = David")
|
19
|
+
$stdout.expects(:puts).with(in_reverse_video "person.name = David")
|
15
20
|
ql :"person.name"
|
16
21
|
end
|
22
|
+
|
23
|
+
def test_log_string
|
24
|
+
$stdout.expects(:puts).with(in_reverse_video "my message")
|
25
|
+
ql "my message"
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_log_object_convertible_to_string
|
29
|
+
$stdout.expects(:puts).with(in_reverse_video "2")
|
30
|
+
ql 2
|
31
|
+
end
|
32
|
+
|
17
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quicklog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florent Guilleux
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|