praise 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +3 -3
  2. data/README_FULL.md +4 -3
  3. data/lib/praise.rb +24 -2
  4. metadata +1 -1
data/README.md CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  Pry + raise = praise. A small gem for intercepting raise calls to dig up hidden and buried exceptions.
4
4
 
5
- - Documentation: http://blog.pitr.ch/praise
6
- - Source: https://github.com/pitr-ch/praise
7
- - Blog: http://blog.pitr.ch
5
+ - Documentation: <http://blog.pitr.ch/praise>
6
+ - Source: <https://github.com/pitr-ch/praise>
7
+ - Blog: <http://blog.pitr.ch/blog/categories/praise/>
data/README_FULL.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  Pry + raise = praise. A small gem for intercepting raise calls to dig up hidden and buried exceptions.
4
4
 
5
- - Documentation: {http://blog.pitr.ch/praise}
6
- - Source: {https://github.com/pitr-ch/praise}
7
- - Blog: {http://blog.pitr.ch}
5
+ - Documentation: <http://blog.pitr.ch/praise>
6
+ - Source: <https://github.com/pitr-ch/praise>
7
+ - Blog: <http://blog.pitr.ch/blog/categories/praise/>
8
8
 
9
9
  ## Difference between `prise` and `pry-rescue`
10
10
 
@@ -20,6 +20,7 @@ investigation of these exceptions.
20
20
 
21
21
  Praise = PraiseImpl.
22
22
  new(File.join(root, Katello.early_config.praise.ignored_path),
23
+ true,
23
24
  -> level, message { Logging.logger['praise'].add Logging.level_num(level), message })
24
25
 
25
26
  And that's it.
data/lib/praise.rb CHANGED
@@ -3,21 +3,26 @@ require 'pry-stack_explorer'
3
3
  require 'yaml'
4
4
 
5
5
  class PraiseImpl
6
+ attr_reader :enabled
7
+
6
8
  # @param [Proc] outputter a proc which ouputs/logs messages
9
+ # @param [true, false] enabled
7
10
  # @param [String] ignored_path path to a yaml file with rules for ignored exceptions
8
11
  # @example initialization
9
12
  # Praise = PraiseImpl.
10
13
  # new(File.join(root, Katello.early_config.praise.ignored_path),
11
14
  # -> level, message { Logging.logger['praise'].add Logging.level_num(level), message })
12
- def initialize(ignored_path, outputter = -> level, message { $stderr.puts message })
15
+ def initialize(ignored_path, enabled = true, outputter = -> level, message { $stderr.puts message })
13
16
  @outputter = outputter
14
17
  unless File.exist? ignored_path
15
18
  log :info, "creating #{ignored_path} file"
16
19
  File.open(ignored_path, 'w') { |f| f.write [].to_yaml }
17
20
  end
18
21
  @ignored_path = ignored_path
22
+ @enabled = false
19
23
  reload
20
- install
24
+
25
+ self.enabled = enabled
21
26
  end
22
27
 
23
28
  # @return [Array<Hash{:class, :message, :line => Regexp, String}>] rules for exception ignoring
@@ -33,6 +38,17 @@ class PraiseImpl
33
38
  reload
34
39
  end
35
40
 
41
+ # use to enable or disable Praise
42
+ def enabled=(value)
43
+ return if @enabled == value
44
+
45
+ if value
46
+ install
47
+ else
48
+ uninstall
49
+ end
50
+ end
51
+
36
52
  # @return [true, false] should the exception ignored?
37
53
  def ignore?(exception_instance, message, risen_at)
38
54
  ignored.any? do |hash|
@@ -100,4 +116,10 @@ class PraiseImpl
100
116
  end
101
117
  self
102
118
  end
119
+
120
+ def uninstall
121
+ Kernel.module_eval do
122
+ define_method :raise, Kernel.instance_method(:_original_raise)
123
+ end
124
+ end
103
125
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: praise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: