lamian 0.2.0 → 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: 3c25553f88b3b5fc9b4a29a6e851f099e3c8384d
4
- data.tar.gz: 033dbf2949a2b4a495311756fed3c4acbefceac3
3
+ metadata.gz: af55048dfae57a8cb4c142cc91a3e184a840df54
4
+ data.tar.gz: 259f504ea8d043659adfa66a736974e6f1c0d344
5
5
  SHA512:
6
- metadata.gz: 037040f26b0fda2927d85b2351b7b944b7fa4b404fee7e4a9792bfaf039cffa44380d37e0297f98446fbbb000a9894c657a19ae161d87b6ea04ef54506f7df2b
7
- data.tar.gz: 6155210a40ccbfb2764186d1fb36b2d96d73dcb9f09082ef95b75212fc8b79a71ca55f514a931039adcee36e587305ad188a10aef99345e300cd6657b9303ba0
6
+ metadata.gz: 605dcc50b3472cd341dd9ea3f8aceae8a0c180679f19bf86189d1c02783d61eba98ef6ce7096cf25851de11bbfb5137633e3cd544793bf5999d388dafc73e949
7
+ data.tar.gz: a5b1b27b04d6bcb2a184c8a4acb4e1dec2f2f99f650fb605ca5e7c49e57ad408c23fc9cda35dbdd013d24d780021520bc056b734549ae65ab2ffecb14246fa90
data/lib/lamian.rb CHANGED
@@ -25,20 +25,12 @@ module Lamian
25
25
  Lamian::Logger.current
26
26
  end
27
27
 
28
- def start(&block)
29
- logger.start(&block)
28
+ def run
29
+ logger.run { yield }
30
30
  end
31
31
 
32
- def reset
33
- logger.reset
34
- end
35
-
36
- def dump(*args, &block)
37
- logger.dump(*args, &block)
38
- end
39
-
40
- def stop
41
- logger.stop
32
+ def dump
33
+ logger.dump
42
34
  end
43
35
  end
44
36
  end
data/lib/lamian/config.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'logger'
2
3
 
3
4
  module Lamian
data/lib/lamian/engine.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'rails'
2
3
  require 'exception_notification'
3
4
  require 'exception_notification/rails'
data/lib/lamian/logger.rb CHANGED
@@ -8,60 +8,50 @@ module Lamian
8
8
  Thread.current[:__lamian_logger] ||= new
9
9
  end
10
10
 
11
- def initialize(running = false)
12
- self.running = running
11
+ def initialize
13
12
  self.level = 0
14
- reset
13
+ self.logdevs = []
14
+ self.formatter = Lamian.config.formatter
15
15
  end
16
16
 
17
- def start
18
- if block_given?
19
- run_with_separate_logdev { yield }
20
- else
21
- reset
22
- self.running = true
23
- end
17
+ def run
18
+ push_logdev(StringIO.new)
19
+ yield
20
+ ensure
21
+ pop_logdev
24
22
  end
25
23
 
26
- def reset
27
- self.logdev = StringIO.new
24
+ def add(*args, &block)
25
+ each_logdev { super(*args, &block) }
28
26
  end
29
27
 
30
28
  def dump(format: nil)
31
- result = block_given? ? run_with_separate_logdev { yield } : logdev.string.dup
32
- format ? prepare_output(format, result) : result
29
+ result = logdevs[-1].string.dup
30
+ formatter ? apply_format(format, result) : result
33
31
  end
34
32
 
35
- def stop
36
- self.running = false
37
- dump
38
- end
33
+ private
39
34
 
40
- def add(*)
41
- return unless running?
42
- self.formatter = Lamian.config.formatter
43
- super
44
- end
35
+ attr_accessor :level, :logdevs, :formatter
45
36
 
46
- private
37
+ def apply_format(_format, result)
38
+ result.gsub!(/\[\d{1,2}m/)
39
+ result
40
+ end
47
41
 
48
- def prepare_output(_format, text)
49
- text.gsub!(/\[\d{1,2}m/, '')
50
- text
42
+ def push_logdev(logdev)
43
+ logdevs << logdev
51
44
  end
52
45
 
53
- attr_accessor :running, :logdev, :level, :formatter
54
- alias running? running
46
+ def pop_logdev
47
+ logdevs.pop
48
+ end
55
49
 
56
- def run_with_separate_logdev
57
- old_logdev = logdev
58
- old_running = running?
59
- start
60
- yield
61
- stop
62
- ensure
63
- self.logdev = old_logdev
64
- self.running = old_running
50
+ def each_logdev
51
+ logdevs.each do |logdev|
52
+ @logdev = logdev
53
+ yield
54
+ end
65
55
  end
66
56
  end
67
57
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Lamian
2
3
  class Middleware
3
4
  def initialize(app)
@@ -5,9 +6,7 @@ module Lamian
5
6
  end
6
7
 
7
8
  def call(env)
8
- result = []
9
- Lamian.start { result = app.call(env) }
10
- result
9
+ Lamian.run { app.call(env) }
11
10
  end
12
11
 
13
12
  private
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Lamian
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lamian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JelF
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-21 00:00:00.000000000 Z
11
+ date: 2016-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.10'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.8'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.8'
111
125
  description: Add logs to your error messages, using exception_notifier or smth like
112
126
  it
113
127
  email:
@@ -149,4 +163,3 @@ signing_key:
149
163
  specification_version: 4
150
164
  summary: Add logs to your error messages
151
165
  test_files: []
152
- has_rdoc: