treefell 0.2.1 → 0.2.2

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: ea76363254edab4bb829968b2c0fb9d2dc90fde6
4
- data.tar.gz: 74e9362162ccda25940714e018b09f2f4edd9fb6
3
+ metadata.gz: 0b320702819874e40877795f4d957ea40005f1d5
4
+ data.tar.gz: f1465485137b21ef81b966d8f52445e8d061e3eb
5
5
  SHA512:
6
- metadata.gz: 42bb9c5006d8b891d60239a9ab0f52221b7fd2de543be7815978fd074d9b220a748b643371c3235b9bbc50360958e7f9c6450728f7c49ac10b1d4b286444d0d6
7
- data.tar.gz: f9779ffb54792922170e4af30c8f4edbe160255f9c75732b99657fc16fc9da9bccfb991310f9ca9768638c34ef0fc58ca51a1e3e38fb6ff273914cfa3eb7b259
6
+ metadata.gz: eb745fcba0d098d68bc6178c0463efcdc1587b716571b4b78759e07c0cdcb62456e27123dfd773c97cc3b73ed1ccfd5fdbe6e9c1cd90edabb847dec13cfd9b3a
7
+ data.tar.gz: 037a0b798d1ec0274683282ad90127b440b0ef672201bb4354ad00cd428707922d9f46366485a17fd0b89813bd0ff0086d605de72904c941a89299f70544b126
@@ -1,33 +1,29 @@
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
6
  WILDCARD = '*'
5
7
 
6
- attr_reader :var_name
7
-
8
- def initialize(var_name:)
9
- @var_name = var_name
8
+ def initialize(value: ENV_VAR_LOOKUP)
9
+ @value_proc = value
10
10
  end
11
11
 
12
12
  def call(namespace, message)
13
- value = ENV[@var_name]
13
+ @value = @value_proc.call
14
14
  is_mentioned?(namespace)
15
15
  is_mentioned?(namespace) || is_mentioned?(WILDCARD)
16
16
  end
17
17
 
18
18
  def ==(other)
19
19
  other.is_a?(self.class) &&
20
- other.var_name == var_name
20
+ other.instance_variable_get(:@value_proc) == @value_proc
21
21
  end
22
22
 
23
23
  private
24
24
 
25
- def var_value
26
- @var_value ||= ENV[@var_name]
27
- end
28
-
29
25
  def is_mentioned?(str)
30
- var_value.to_s.split(/\s*,\s*/).include?(str)
26
+ @value.to_s.split(/\s*,\s*/).include?(str)
31
27
  end
32
28
  end
33
29
  end
@@ -1,3 +1,3 @@
1
1
  module Treefell
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
data/lib/treefell.rb CHANGED
@@ -5,21 +5,31 @@ require 'treefell/debug_logger'
5
5
  require 'treefell/filters/env_filter'
6
6
 
7
7
  module Treefell
8
- DEFAULT_ENV_VAR = 'DEBUG'
8
+ ENV_VAR_LOOKUP = -> { ENV[Treefell.env_var] }
9
9
 
10
10
  def self.env_var=(env_var)
11
11
  @env_var = env_var
12
12
  end
13
13
 
14
14
  def self.env_var
15
- @env_var || DEFAULT_ENV_VAR
15
+ @env_var || Treefell::EnvFilter::ENV_VAR_KEY
16
16
  end
17
17
 
18
18
  def self.debug(namespace=nil, io: $stdout, filter: nil)
19
- DebugLogger.new(
19
+ filter ||= Filters::EnvFilter.new(value: ENV_VAR_LOOKUP)
20
+ @debug_loggers ||= {}
21
+ @debug_loggers[namespace] ||= DebugLogger.new(
20
22
  namespace: namespace,
21
23
  io: io,
22
- filter: (filter || Filters::EnvFilter.new(var_name: env_var))
24
+ filter: filter
23
25
  )
24
26
  end
27
+
28
+ def self.reset
29
+ @debug_loggers.clear
30
+ end
31
+
32
+ def self.[](namespace)
33
+ debug(namespace)
34
+ end
25
35
  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.2.1
4
+ version: 0.2.2
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-07 00:00:00.000000000 Z
11
+ date: 2016-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: term-ansicolor