dont 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +55 -5
  3. data/lib/dont.rb +5 -3
  4. data/lib/dont/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24d5eabf7ad968cb3d575076d120bf5ccc4808ae
4
- data.tar.gz: f7dc01339e3629f8cad5ed1cfc3297afd4c0f0b9
3
+ metadata.gz: 0156e22abab96bdf2ddbd0356e4cbac463db8768
4
+ data.tar.gz: fe0a0d6111137d0afe9b54f8d015ae70ec0a6f59
5
5
  SHA512:
6
- metadata.gz: 5c2a8cf3e08e5aed86eff61fb3af1d1b612c9a56c9ca46c8655abe7ceb16904734b2f8c0e9a97cf77e6a090a752a6b303f2af693a359e6a42a8f15a6ecfd67b6
7
- data.tar.gz: ff10f1eb7399ee41889c758e8d47c3ee87b410fafabd9a894e16c090fef129c7eadd37c04a4e83620c38174084fc064e2155093b879991a72dee28c644a7b9ed
6
+ metadata.gz: b5db40d42d4f9f50b99a3afa562dcde408fb17cf6e657db25208897b11a533a0f88d885da1f93a4d046a8ecb44b63495b244135af9c3ab3f4d8c10716acc273d
7
+ data.tar.gz: 903ce70655179694dd581f4d7f2e9d98fcc2e200198853d69756a111ce7252519460c2903389d3218cc4a798fbbebe65066596108ebea2de5889f6b39e6b747a
data/README.md CHANGED
@@ -22,13 +22,36 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
+ ```ruby
26
+ class Shouter
27
+ include Dont::WithWarn
28
+
29
+ def shout(msg)
30
+ msg.upcase
31
+ end
32
+
33
+ def scream(msg)
34
+ shout(msg)
35
+ end
36
+ # Indicate that we want to deprecate the scream method, and that you should
37
+ # use "shout" instead. The :use option can be any string or symbol.
38
+ dont_use :scream, use: :shout
39
+ end
40
+
41
+ # Logs "DEPRECATED: Don't use Shouter#scream. It's deprecated in favor of shout.",
42
+ # before executing the method.
43
+ Shouter.new.scream("hello")
44
+ ```
45
+
46
+ ### With a custom handler
47
+
25
48
  ```ruby
26
49
  # Register a deprecation handler.
27
50
  # Anything that responds to `.call(deprecation)` will work.
28
51
  LOGGER = Logger.new
29
- Dont.register_handler(:logger, ->(deprecation) { LOGGER.warn(deprecation.message) })
52
+ DeprecationLogger = Dont.register_handler(:logger, ->(deprecation) { LOGGER.warn(deprecation.message) })
30
53
  class Shouter
31
- include Dont.new(:logger)
54
+ include DeprecationLogger
32
55
 
33
56
  def shout(msg)
34
57
  msg.upcase
@@ -40,16 +63,19 @@ class Shouter
40
63
  dont_use :scream, use: :shout
41
64
  end
42
65
 
43
- # Logs "DEPRECATED: Don't use Shouter#scream. It's deprecated in favor of
44
- # shout.", before executing the method.
66
+ # Logs "DEPRECATED: Don't use Shouter#scream. It's deprecated in favor of shout.",
67
+ # before executing the method.
45
68
  Shouter.new.scream("hello")
69
+ ```
46
70
 
71
+ ### Raising exceptions in development
47
72
 
73
+ ```
48
74
  # The :exception deprecation handler is provided by default.
49
75
  # It raises an exception whenever the method is called, which is handy in
50
76
  # test or development mode.
51
77
  class Person
52
- include Dont.new(:exception)
78
+ include Dont::WithException
53
79
 
54
80
  attr_accessor :firstname
55
81
  attr_accessor :first_name
@@ -59,6 +85,30 @@ end
59
85
  Person.new.firstname # => fails with Dont::DeprecationError
60
86
  ```
61
87
 
88
+ ### Using the Rails logger
89
+
90
+ ```ruby
91
+ # in config/initializers/dont.rb
92
+ Dont.register_handler(:rails_logger, ->(deprecation) {
93
+ Rails.logger.warn(deprecation.message)
94
+ })
95
+ DontLogger = Dont.new(:rails_logger)
96
+
97
+ # in app/models/comment.rb
98
+ class Comment < ActiveRecord::Base
99
+ include DontLogger # as defined in the initializer
100
+
101
+ # We want to use `body` instead of `description` from now on
102
+ alias_attribute :description, :body
103
+ dont_use :description, use: :body
104
+ end
105
+
106
+ comment = Comment.new
107
+ comment.description
108
+ # => works, but with a deprecation warning: "DEPRECATED: Don't use Comment#description. It's deprecated in favor of body."
109
+
110
+ ```
111
+
62
112
  ## Development
63
113
 
64
114
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -128,7 +128,9 @@ class Dont < Module
128
128
  end
129
129
  end
130
130
 
131
- register_handler(:exception, -> (deprecation) {
132
- fail Dont::DeprecationError, deprecation.message
133
- })
131
+ register_handler(:exception, -> (deprecation) { fail Dont::DeprecationError, deprecation.message })
132
+ register_handler(:warn, -> (deprecation) { warn deprecation.message })
133
+
134
+ WithException = new(:exception)
135
+ WithWarn = new(:warn)
134
136
  end
@@ -1,3 +1,3 @@
1
1
  class Dont < Module
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.2.1".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dont
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maarten Claes
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-10 00:00:00.000000000 Z
11
+ date: 2016-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-container