|
69 | 69 | # end |
70 | 70 | # end |
71 | 71 |
|
72 | | -module Gem::Deprecate |
73 | | - def self.skip # :nodoc: |
74 | | - @skip ||= false |
75 | | - end |
| 72 | +module Gem |
| 73 | + module Deprecate |
| 74 | + def self.skip # :nodoc: |
| 75 | + @skip ||= false |
| 76 | + end |
76 | 77 |
|
77 | | - def self.skip=(v) # :nodoc: |
78 | | - @skip = v |
79 | | - end |
| 78 | + def self.skip=(v) # :nodoc: |
| 79 | + @skip = v |
| 80 | + end |
80 | 81 |
|
81 | | - ## |
82 | | - # Temporarily turn off warnings. Intended for tests only. |
| 82 | + ## |
| 83 | + # Temporarily turn off warnings. Intended for tests only. |
83 | 84 |
|
84 | | - def skip_during |
85 | | - original = Gem::Deprecate.skip |
86 | | - Gem::Deprecate.skip = true |
87 | | - yield |
88 | | - ensure |
89 | | - Gem::Deprecate.skip = original |
90 | | - end |
| 85 | + def skip_during |
| 86 | + original = Gem::Deprecate.skip |
| 87 | + Gem::Deprecate.skip = true |
| 88 | + yield |
| 89 | + ensure |
| 90 | + Gem::Deprecate.skip = original |
| 91 | + end |
91 | 92 |
|
92 | | - def self.next_rubygems_major_version # :nodoc: |
93 | | - Gem::Version.new(Gem.rubygems_version.segments.first).bump |
94 | | - end |
| 93 | + def self.next_rubygems_major_version # :nodoc: |
| 94 | + Gem::Version.new(Gem.rubygems_version.segments.first).bump |
| 95 | + end |
95 | 96 |
|
96 | | - ## |
97 | | - # Simple deprecation method that deprecates +name+ by wrapping it up |
98 | | - # in a dummy method. It warns on each call to the dummy method |
99 | | - # telling the user of +repl+ (unless +repl+ is :none) and the |
100 | | - # year/month that it is planned to go away. |
| 97 | + ## |
| 98 | + # Simple deprecation method that deprecates +name+ by wrapping it up |
| 99 | + # in a dummy method. It warns on each call to the dummy method |
| 100 | + # telling the user of +repl+ (unless +repl+ is :none) and the |
| 101 | + # year/month that it is planned to go away. |
101 | 102 |
|
102 | | - def deprecate(name, repl, year, month) |
103 | | - class_eval do |
104 | | - old = "_deprecated_#{name}" |
105 | | - alias_method old, name |
106 | | - define_method name do |*args, &block| |
107 | | - klass = is_a? Module |
108 | | - target = klass ? "#{self}." : "#{self.class}#" |
109 | | - msg = [ |
110 | | - "NOTE: #{target}#{name} is deprecated", |
111 | | - repl == :none ? " with no replacement" : "; use #{repl} instead", |
112 | | - format(". It will be removed on or after %4d-%02d.", year, month), |
113 | | - "\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}", |
114 | | - ] |
115 | | - warn "#{msg.join}." unless Gem::Deprecate.skip |
116 | | - send old, *args, &block |
| 103 | + def deprecate(name, repl, year, month) |
| 104 | + class_eval do |
| 105 | + old = "_deprecated_#{name}" |
| 106 | + alias_method old, name |
| 107 | + define_method name do |*args, &block| |
| 108 | + klass = is_a? Module |
| 109 | + target = klass ? "#{self}." : "#{self.class}#" |
| 110 | + msg = [ |
| 111 | + "NOTE: #{target}#{name} is deprecated", |
| 112 | + repl == :none ? " with no replacement" : "; use #{repl} instead", |
| 113 | + format(". It will be removed on or after %4d-%02d.", year, month), |
| 114 | + "\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}", |
| 115 | + ] |
| 116 | + warn "#{msg.join}." unless Gem::Deprecate.skip |
| 117 | + send old, *args, &block |
| 118 | + end |
| 119 | + ruby2_keywords name if respond_to?(:ruby2_keywords, true) |
117 | 120 | end |
118 | | - ruby2_keywords name if respond_to?(:ruby2_keywords, true) |
119 | 121 | end |
120 | | - end |
121 | 122 |
|
122 | | - ## |
123 | | - # Simple deprecation method that deprecates +name+ by wrapping it up |
124 | | - # in a dummy method. It warns on each call to the dummy method |
125 | | - # telling the user of +repl+ (unless +repl+ is :none) and the |
126 | | - # Rubygems version that it is planned to go away. |
| 123 | + ## |
| 124 | + # Simple deprecation method that deprecates +name+ by wrapping it up |
| 125 | + # in a dummy method. It warns on each call to the dummy method |
| 126 | + # telling the user of +repl+ (unless +repl+ is :none) and the |
| 127 | + # Rubygems version that it is planned to go away. |
127 | 128 |
|
128 | | - def rubygems_deprecate(name, replacement=:none) |
129 | | - class_eval do |
130 | | - old = "_deprecated_#{name}" |
131 | | - alias_method old, name |
132 | | - define_method name do |*args, &block| |
133 | | - klass = is_a? Module |
134 | | - target = klass ? "#{self}." : "#{self.class}#" |
135 | | - msg = [ |
136 | | - "NOTE: #{target}#{name} is deprecated", |
137 | | - replacement == :none ? " with no replacement" : "; use #{replacement} instead", |
138 | | - ". It will be removed in Rubygems #{Gem::Deprecate.next_rubygems_major_version}", |
139 | | - "\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}", |
140 | | - ] |
141 | | - warn "#{msg.join}." unless Gem::Deprecate.skip |
142 | | - send old, *args, &block |
| 129 | + def rubygems_deprecate(name, replacement=:none) |
| 130 | + class_eval do |
| 131 | + old = "_deprecated_#{name}" |
| 132 | + alias_method old, name |
| 133 | + define_method name do |*args, &block| |
| 134 | + klass = is_a? Module |
| 135 | + target = klass ? "#{self}." : "#{self.class}#" |
| 136 | + msg = [ |
| 137 | + "NOTE: #{target}#{name} is deprecated", |
| 138 | + replacement == :none ? " with no replacement" : "; use #{replacement} instead", |
| 139 | + ". It will be removed in Rubygems #{Gem::Deprecate.next_rubygems_major_version}", |
| 140 | + "\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}", |
| 141 | + ] |
| 142 | + warn "#{msg.join}." unless Gem::Deprecate.skip |
| 143 | + send old, *args, &block |
| 144 | + end |
| 145 | + ruby2_keywords name if respond_to?(:ruby2_keywords, true) |
143 | 146 | end |
144 | | - ruby2_keywords name if respond_to?(:ruby2_keywords, true) |
145 | 147 | end |
146 | | - end |
147 | 148 |
|
148 | | - # Deprecation method to deprecate Rubygems commands |
149 | | - def rubygems_deprecate_command(version = Gem::Deprecate.next_rubygems_major_version) |
150 | | - class_eval do |
151 | | - define_method "deprecated?" do |
152 | | - true |
153 | | - end |
| 149 | + # Deprecation method to deprecate Rubygems commands |
| 150 | + def rubygems_deprecate_command(version = Gem::Deprecate.next_rubygems_major_version) |
| 151 | + class_eval do |
| 152 | + define_method "deprecated?" do |
| 153 | + true |
| 154 | + end |
154 | 155 |
|
155 | | - define_method "deprecation_warning" do |
156 | | - msg = [ |
157 | | - "#{command} command is deprecated", |
158 | | - ". It will be removed in Rubygems #{version}.\n", |
159 | | - ] |
| 156 | + define_method "deprecation_warning" do |
| 157 | + msg = [ |
| 158 | + "#{command} command is deprecated", |
| 159 | + ". It will be removed in Rubygems #{version}.\n", |
| 160 | + ] |
160 | 161 |
|
161 | | - alert_warning msg.join.to_s unless Gem::Deprecate.skip |
| 162 | + alert_warning msg.join.to_s unless Gem::Deprecate.skip |
| 163 | + end |
162 | 164 | end |
163 | 165 | end |
164 | | - end |
165 | 166 |
|
166 | | - module_function :rubygems_deprecate, :rubygems_deprecate_command, :skip_during |
| 167 | + module_function :rubygems_deprecate, :rubygems_deprecate_command, :skip_during |
| 168 | + end |
167 | 169 | end |
0 commit comments