-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.rb
47 lines (45 loc) · 1.56 KB
/
module.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#---
# Excerpted from "Metaprogramming Ruby 2",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material,
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose.
# Visit http://www.pragmaticprogrammer.com/titles/ppmetr2 for more book information.
#---
require 'rake/ext/core'
require 'rake/task'
require 'rake/file_task'
require 'rake/file_creation_task'
require 'rake/application'
require 'rake/task_manager'
######################################################################
# Rake extensions to Module.
#
class Module
# Rename the original handler to make it available.
alias :rake_original_const_missing :const_missing
# Check for deprecated uses of top level (i.e. in Object) uses of
# Rake class names. If someone tries to reference the constant
# name, display a warning and return the proper object. Using the
# --classic-namespace command line option will define these
# constants in Object and avoid this handler.
def const_missing(const_name)
case const_name
when :Task
Rake.application.const_warning(const_name)
Rake::Task
when :FileTask
Rake.application.const_warning(const_name)
Rake::FileTask
when :FileCreationTask
# ...
Rake.application.const_warning(const_name)
Rake::FileCreationTask
when :RakeApp
Rake.application.const_warning(const_name)
Rake::Application
else
rake_original_const_missing(const_name)
end
end
end