treefell 0.1.0 → 0.2.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: 801d13dd8ee8f4a572d05c6a011896ffa7dbbb0a
4
- data.tar.gz: 9768f42505d92fafcc19bdb88be5a687a5099934
3
+ metadata.gz: 5745e3caccbe0ff653e2c344026449e89f25b9a8
4
+ data.tar.gz: d1a56ec23c658d3667861fff6cc6e68f0536a9b9
5
5
  SHA512:
6
- metadata.gz: 0b8a23f86d3adfad3c3dbe5cdfe6570c571ebbd72ab22c6619a6355ed4cdb609e503a7e9c5a9de46ad0be8ae9e9b992cb5ecf3d50a2051516d2cf8cd0646e019
7
- data.tar.gz: 531c98a230201a4405276500f49241f301fc317599873f38e1d80ff22b410150dfb0006da245f047d0f8b0535e54894039cf01dae6b0dea538e0a00c261413af
6
+ metadata.gz: e651ebdc9de8a59613b497d1d1f30acc7ffa1718ce37248454b8e9c3f434c4479f08e33a367842bc2efb396a4f19c7e0eeedb49ecaa81fcfd2d8f306f7b7d496
7
+ data.tar.gz: 1f947d9dd519d4d7898ca603cafb1090d35ac81c182bbdbc0c85d70b636de6d6708fcf7819884cdfaa75eecc2c168ebad33131dc38d9dad4e7925f60c626dbc3
data/lib/tasks/gem.rake CHANGED
@@ -2,7 +2,7 @@ namespace :bump do
2
2
  namespace :version do
3
3
  class ProjectVersion
4
4
  FILE = File.dirname(__FILE__) + '/../treefell/version.rb'
5
- PATTERN = /VERSION\s*=\s*"(\d+)\.(\d+)\.(\d+)"/m
5
+ PATTERN = /VERSION\s*=\s*['"](\d+)\.(\d+)\.(\d+)['"]/m
6
6
 
7
7
  def initialize(file=FILE, pattern=PATTERN)
8
8
  @file = file
@@ -2,28 +2,33 @@ require 'treefell/color'
2
2
 
3
3
  module Treefell
4
4
  class DebugLogger
5
- attr_reader :io, :namespace
5
+ DEFAULT_FILTER_PROC = proc { true }
6
+ attr_reader :filter, :io, :namespace
6
7
 
7
- def initialize(namespace: nil, io: $stdout, color: Color.rotate)
8
+ def initialize(namespace: nil, io: $stdout, color: Color.rotate, filter: nil)
8
9
  @namespace = namespace
9
10
  @io = io
10
11
  @color = color
12
+ @filter = filter || DEFAULT_FILTER_PROC
11
13
  end
12
14
 
13
15
  def puts(message)
14
- formatted_namespace = if namespace
15
- @color.colorize(namespace)
16
+ if @filter.call(namespace, message)
17
+ formatted_namespace = if namespace
18
+ @color.colorize(namespace)
19
+ end
20
+ @io.puts [
21
+ formatted_namespace,
22
+ message
23
+ ].compact.join(' ')
16
24
  end
17
- @io.puts [
18
- formatted_namespace,
19
- message
20
- ].compact.join(' ')
21
25
  end
22
26
 
23
27
  def ==(other)
24
- other.is_a?(DebugLogger) &&
28
+ other.is_a?(self.class) &&
25
29
  other.namespace == namespace &&
26
- other.io == io
30
+ other.io == io &&
31
+ other.filter == filter
27
32
  end
28
33
  end
29
34
  end
@@ -0,0 +1,27 @@
1
+ module Treefell
2
+ module Filters
3
+ class EnvFilter
4
+ attr_reader :var_name
5
+
6
+ def initialize(var_name:)
7
+ @var_name = var_name
8
+ end
9
+
10
+ def call(namespace, message)
11
+ return true if is_namespace_mentioned_in_env_var?(namespace)
12
+ false
13
+ end
14
+
15
+ def ==(other)
16
+ other.is_a?(self.class) &&
17
+ other.var_name == var_name
18
+ end
19
+
20
+ private
21
+
22
+ def is_namespace_mentioned_in_env_var?(namespace)
23
+ ENV[@var_name].to_s.split(/\s*,\s*/).include?(namespace)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module Treefell
2
- VERSION = '0.1.0'
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/treefell.rb CHANGED
@@ -2,9 +2,24 @@ require 'term/ansicolor'
2
2
 
3
3
  require 'treefell/version'
4
4
  require 'treefell/debug_logger'
5
+ require 'treefell/filters/env_filter'
5
6
 
6
7
  module Treefell
8
+ DEFAULT_ENV_VAR = 'DEBUG'
9
+
10
+ def self.env_var=(env_var)
11
+ @env_var = env_var
12
+ end
13
+
14
+ def self.env_var
15
+ @env_var || DEFAULT_ENV_VAR
16
+ end
17
+
7
18
  def self.debug(namespace=nil, io: $stdout)
8
- DebugLogger.new(namespace: namespace, io: io)
19
+ DebugLogger.new(
20
+ namespace: namespace,
21
+ io: io,
22
+ filter: Filters::EnvFilter.new(var_name: env_var)
23
+ )
9
24
  end
10
25
  end
data/treefell.gemspec CHANGED
@@ -22,4 +22,5 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.add_dependency "term-ansicolor", "~> 1.3"
24
24
  s.add_development_dependency 'rspec', '~> 3.4.0', '>= 3.4'
25
+ s.add_development_dependency 'climate_control', '~> 0.0.3'
25
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: treefell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.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-06 00:00:00.000000000 Z
11
+ date: 2016-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: term-ansicolor
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '3.4'
47
+ - !ruby/object:Gem::Dependency
48
+ name: climate_control
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 0.0.3
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.0.3
47
61
  description: Treefell is a simple debug-logging library for ruby.
48
62
  email: zach.dennis@gmail.com
49
63
  executables: []
@@ -56,6 +70,7 @@ files:
56
70
  - lib/treefell.rb
57
71
  - lib/treefell/color.rb
58
72
  - lib/treefell/debug_logger.rb
73
+ - lib/treefell/filters/env_filter.rb
59
74
  - lib/treefell/version.rb
60
75
  - treefell.gemspec
61
76
  homepage: https://github.com/zdennis/treefell