treefell 0.2.3 → 0.3.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: aa7207780fff940842ef702f33321ad8e07fff43
4
- data.tar.gz: 4b7c5f201aa20cfed884557d3c5fac5f6ba26dff
3
+ metadata.gz: ebeb16ac49693f30536f49f3bf7de672c83d8ebd
4
+ data.tar.gz: fab978b8ea55f12886bef500dc405bdaec51e6dd
5
5
  SHA512:
6
- metadata.gz: 180419544eea4e9eb0d3047000b3740c63618014ce33587cf9f0080efecc72c3ea33d1a3909f1e8f20339c7d826ab57b53891d7ac844e075fc24c0ff8715e809
7
- data.tar.gz: 04cd2b4f0bcee70945b4cb4c808e685dcab9ba49e950495889ce031bfa4d361392370cd976f4a606aa8925cd73e53d5cb1b1ee97c234ac899c50523cd7e39d00
6
+ metadata.gz: dd51cc55d02e9f3dc966ce7990fca5fe8de0014209a9dd91fc61311b9353a7d9eef3b982a22b4090d3533aa408c66ef3c21a3151b41c2f29fe1ce93ecd7e880d
7
+ data.tar.gz: 479759a67145d4cbd0c46f354b1d92aaa7a9ef2bda799ddbf433f35962a5ce45ae72bc2482dcd18c0623443b7153060cc8c0220523621cacc8908837b371f932
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Treefell [![Build Status](https://travis-ci.org/zdennis/treefell.svg?branch=master)](https://travis-ci.org/zdennis/treefell)
2
2
 
3
- Treefell is a simple debug-logging library for ruby.
3
+ > If a tree falls in a forest and no one is around to hear it, does it make a sound?
4
+
5
+ Treefell is a minimalist debug-logging library for ruby. It uses the DEBUG environment variable to determine which debug messages are logged and which are suppressed.
6
+
7
+ This project was inspired by visionmedia's [debug](https://github.com/visionmedia/debug) library for nodejs.
4
8
 
5
9
  ## Installation
6
10
 
@@ -18,7 +22,76 @@ Or install it yourself as:
18
22
 
19
23
  ## Usage
20
24
 
21
- TODO: Write usage instructions here
25
+ Take the ruby program:
26
+
27
+ ```ruby
28
+ #!/usr/bin/env ruby
29
+
30
+ require 'treefell'
31
+
32
+ foo_debug = Treefell['foo']
33
+ foo_debug.puts 'too funky in here'
34
+
35
+ bar_debug = Treefell['bar']
36
+ bar_debug.puts 'you got that right'
37
+
38
+ baz_debug = Treefell['baz']
39
+ baz_debug.puts 'say it again'
40
+ ```
41
+
42
+ Each call to `Treefell['...']` instantiates a `DebugLogger` for the provided
43
+ namespace (e.g. foo, bar, baz).
44
+
45
+ By default no debug log statements are displayed:
46
+
47
+ ```
48
+ > ruby program.rb
49
+ ```
50
+
51
+ ### Displaying all messages
52
+
53
+ You can tell it to display all messages with the wildcard `*`:
54
+
55
+ ![Example 1 Screenshot](/examples/example_1.png?raw=true)
56
+
57
+ ### Displaying messages from a particular namespace
58
+
59
+ Here's how to display messages for one specific debugging namespace:
60
+
61
+ ![Example 2 Screenshot](/examples/example_2.png?raw=true)
62
+
63
+ ### Displaying messages for multiple namespaces
64
+
65
+ To display messages from multiple namespaces use a comma-separated list of
66
+ namespaces:
67
+
68
+ ![Example 3 Screenshot](/examples/example_3.png?raw=true)
69
+
70
+ ### Colored output
71
+
72
+ Every namespace gets a color associated with it to aide in the visual parsing
73
+ of the output. Also `DebugLogger`(s) are cached per namespace so regardless
74
+ of when you refer to the namespace it will always have the same color
75
+ associated with it.
76
+
77
+ E.g.
78
+
79
+ ```ruby
80
+ foo_debug = Treefell['foo']
81
+ other_foo_debug = Treefell['foo']
82
+
83
+ foo_debug.eql?(other_foo_debug) # => true
84
+ ```
85
+
86
+ #### Sending to IO other than STDOUT
87
+
88
+ By default all messages are written to `STDOUT`. You can change this by
89
+ instantiating a debug logger using the `debug` method, e.g.:
90
+
91
+ ```ruby
92
+ foo_debug = Treefell.debug('foo', io: some_io)
93
+ foo_debug.puts 'Get up offa that thing, and dance till you feel better'
94
+ ```
22
95
 
23
96
  ## Contributing
24
97
 
Binary file
Binary file
Binary file
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'treefell'
4
+
5
+ foo_debug = Treefell['foo']
6
+ foo_debug.puts 'too funky in here'
7
+
8
+ bar_debug = Treefell['bar']
9
+ bar_debug.puts 'you got that right'
10
+
11
+ baz_debug = Treefell['baz']
12
+ baz_debug.puts 'say it again'
@@ -12,6 +12,15 @@ module Treefell
12
12
  @filter = filter || DEFAULT_FILTER_PROC
13
13
  end
14
14
 
15
+ def [](sub_namespace)
16
+ @debug_loggers ||= {}
17
+ @debug_loggers[sub_namespace] ||= DebugLogger.new(
18
+ namespace: sub_namespace,
19
+ io: self,
20
+ filter: DEFAULT_FILTER_PROC
21
+ )
22
+ end
23
+
15
24
  def puts(message)
16
25
  if @filter.call(namespace, message)
17
26
  formatted_namespace = if namespace
@@ -1,11 +1,11 @@
1
1
  module Treefell
2
2
  module Filters
3
3
  class EnvFilter
4
- ENV_VAR_KEY = 'DEBUG'
5
- ENV_VAR_LOOKUP = -> { ENV[ENV_VAR_KEY] }
4
+ NAMESPACE_ENV_VAR_KEY = 'DEBUG'
5
+ NAMESPACE_ENV_VAR_LOOKUP = -> { ENV[NAMESPACE_ENV_VAR_KEY] }
6
6
  WILDCARD = '*'
7
7
 
8
- def initialize(value: ENV_VAR_LOOKUP)
8
+ def initialize(value: NAMESPACE_ENV_VAR_LOOKUP)
9
9
  @value_proc = value
10
10
  end
11
11
 
@@ -1,3 +1,3 @@
1
1
  module Treefell
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/treefell.rb CHANGED
@@ -5,18 +5,28 @@ require 'treefell/debug_logger'
5
5
  require 'treefell/filters/env_filter'
6
6
 
7
7
  module Treefell
8
- ENV_VAR_LOOKUP = -> { ENV[Treefell.env_var] }
8
+ NAMESPACE_ENV_VAR_LOOKUP = -> { ENV[Treefell.namespace_env_var] }
9
9
 
10
- def self.env_var=(env_var)
11
- @env_var = env_var
10
+ def self.namespace_env_var=(namespace_env_var)
11
+ @namespace_env_var = namespace_env_var
12
12
  end
13
13
 
14
- def self.env_var
15
- @env_var || Filters::EnvFilter::ENV_VAR_KEY
14
+ def self.namespace_env_var
15
+ @namespace_env_var || Filters::EnvFilter::NAMESPACE_ENV_VAR_KEY
16
16
  end
17
17
 
18
- def self.debug(namespace=nil, io: $stdout, filter: nil)
19
- filter ||= Filters::EnvFilter.new(value: ENV_VAR_LOOKUP)
18
+ def self.debug(namespace=nil, io: nil, filter: nil)
19
+ io ||= begin
20
+ treefell_out = ENV['TREEFELL_OUT']
21
+ if treefell_out
22
+ @treefell_out_io ||= File.open(treefell_out, 'w+').tap do |io|
23
+ io.sync = true
24
+ end
25
+ else
26
+ $stdout
27
+ end
28
+ end
29
+ filter ||= Filters::EnvFilter.new(value: NAMESPACE_ENV_VAR_LOOKUP)
20
30
  @debug_loggers ||= {}
21
31
  @debug_loggers[namespace] ||= DebugLogger.new(
22
32
  namespace: namespace,
@@ -26,8 +36,12 @@ module Treefell
26
36
  end
27
37
 
28
38
  def self.reset
39
+ if @treefell_out_io
40
+ @treefell_out_io.close unless @treefell_out_io.closed?
41
+ @treefell_out_io = nil
42
+ end
29
43
  @debug_loggers.clear if @debug_loggers
30
- @env_var = nil
44
+ @namespace_env_var = nil
31
45
  end
32
46
 
33
47
  def self.[](namespace)
data/treefell.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
21
21
  s.require_paths = ["lib"]
22
22
 
23
+ s.add_dependency "ansi_string", "~> 0.1"
23
24
  s.add_dependency "term-ansicolor", "~> 1.3"
24
25
  s.add_development_dependency 'rspec', '~> 3.4.0', '>= 3.4'
25
26
  s.add_development_dependency 'climate_control', '~> 0.0.3'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: treefell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Dennis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-08 00:00:00.000000000 Z
11
+ date: 2016-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ansi_string
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: term-ansicolor
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,10 @@ extra_rdoc_files: []
66
80
  files:
67
81
  - README.md
68
82
  - Rakefile
83
+ - examples/example_1.png
84
+ - examples/example_2.png
85
+ - examples/example_3.png
86
+ - examples/program.rb
69
87
  - lib/tasks/gem.rake
70
88
  - lib/treefell.rb
71
89
  - lib/treefell/color.rb
@@ -93,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
111
  version: '0'
94
112
  requirements: []
95
113
  rubyforge_project:
96
- rubygems_version: 2.4.5.1
114
+ rubygems_version: 2.5.1
97
115
  signing_key:
98
116
  specification_version: 4
99
117
  summary: Treefell is a simple debug-logging library for ruby