quicklog 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 540c01430363a89c339bf55b650a5563f0dc229b
4
- data.tar.gz: e3509431bcd34d3be8aaff11f1cce7fd6f9aec7e
3
+ metadata.gz: 1ea4068192d43208f2ce33811d13cd5e64508a1e
4
+ data.tar.gz: 1a6abfbbc853782ef0b782986e53280f138bae8d
5
5
  SHA512:
6
- metadata.gz: 89eaaef654497b4d3c705a0df98cb1e1c02f3de6607204b419208abe1437aadf0838e89b039db50a69078a4b7b84129232951ce1242f1a6a2b982a726c963901
7
- data.tar.gz: 6622a0d6323bd05a6aaa6fc529243ad4cb8226ee6b3a7d54db0ff1a31004a06ec741be07de4e8c4d8fcf1ad7543b78b500a3956f5220ebfba18d0014df26f3b5
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`
@@ -1,3 +1,3 @@
1
1
  module Quicklog
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
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 var_symbol
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 var_symbol.to_s, inspector.frame_binding(3)
8
- puts "#{var_symbol} = #{value}"
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 var_symbol
15
- Quicklog.ql var_symbol
25
+ def ql param
26
+ Quicklog.ql param
16
27
  end
17
28
  module_function :ql
18
29
  end
@@ -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
- def test_log_variable_label_and_value
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.1
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-09 00:00:00.000000000 Z
11
+ date: 2013-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler