| Module | Kernel |
| In: |
lib/mack/core_extensions/kernel.rb
|
| FALSE_GEM_NAMES | = | %w{specifications gems doc cache} |
Aliases the deprecated method to the new method and logs a warning.
# File lib/mack/core_extensions/kernel.rb, line 40
40: def alias_deprecated_method(deprecated_method, new_method, version_deprecrated = nil, version_to_be_removed = nil)
41: eval %{
42: def #{deprecated_method}(*args)
43: deprecate_method(:#{deprecated_method}, :#{new_method}, "#{version_deprecrated}", "#{version_to_be_removed}")
44: #{new_method}(*args)
45: end
46: }
47: end
Return the instance of the AssetManager class.
# File lib/mack/core_extensions/kernel.rb, line 25
25: def assets_mgr
26: return Mack::Assets::Manager.instance
27: end
Logs a warning that a method has been deprecated. Warnings will only get logged once.
# File lib/mack/core_extensions/kernel.rb, line 50
50: def deprecate_method(deprecated_method, new_method = nil, version_deprecrated = nil, version_to_be_removed = nil)
51: message = "DEPRECATED: '#{deprecated_method}'."
52: if new_method
53: message << " Please use '#{new_method}' instead."
54: end
55: if version_deprecrated
56: message << " Deprecated in version: '#{version_deprecrated}'."
57: if version_to_be_removed.nil?
58: version_to_be_removed = ">=#{version_deprecrated.succ}"
59: end
60: end
61: if version_to_be_removed
62: message << " To be removed in version: '#{version_to_be_removed}'."
63: end
64: unless Kernel::DeprecatedRegistryList.registered_items.include?(message)
65: Mack.logger.warn(message)
66: Kernel::DeprecatedRegistryList.add(message)
67: end
68: end
# File lib/mack/core_extensions/kernel.rb, line 75
75: def gem(gem_name, *version_requirements)
76: return if FALSE_GEM_NAMES.include?(gem_name)
77: # puts '***************'
78: # puts "gem_name: #{gem_name}"
79:
80: # try to normalize the version requirement string
81: ver = [version_requirements].flatten.first.to_s.strip
82: if ver == nil || ver.empty?
83: ver = '> 0.0.0'
84: else
85: # if the version string starts with number, then prepend = to it (since the developer wants an exact match)
86: ver = "= " + ver if ver[0,1] != '=' && ver[0,1] != '>' && ver[0,1] != '<' && ver[0,1] != '~'
87: end
88:
89: num = ver.match(/\d.+/).to_s
90: op = ver.delete(num).strip
91: op += '=' if op == '='
92:
93: op = '>=' if op == '~>'
94:
95: found_local_gem = false
96:
97: dirs = []
98: Gem.path.each do |p|
99: dirs << Dir.glob(File.join(p, "#{gem_name}*"))
100: end
101: dirs.flatten!
102: dirs.uniq!
103: # puts "Gem.path: #{Gem.path.inspect}"
104: # puts "--------"
105: # puts "dirs: #{dirs.inspect}"
106:
107: dirs.each_with_index do |file, i|
108: file = File.basename(file)
109: # all frozen gem has the pattern [gem_name]-[version]
110: next if !file.include?'-'
111:
112: # make sure we're not loading gem with almost the same name, e.g. "#{gem_name}-foo_bar-0.89.1"
113: file_gem_name = file.match(/\D*-/).to_s
114: next if !file.starts_with?(file_gem_name)
115:
116: # find the version number from the file name
117: file_ver = file.match(/\d.+/).to_s
118:
119: # generate number comparison string that we can evaluate, to make sure that we
120: # pick the correct gem based on the requested version requirements
121:
122: # if we find the match (i.e. the comparison string checks out) then
123: # read the frozen spec file in that directory (so we can see what the require path is)
124: # and prepend the new require path(s) to the global search path.
125: # If we didn't find it, then continue to look (obviously)
126: if eval("'#{file_ver}' #{op} '#{num}'")
127: spec_file = File.join(file, 'spec.yaml')
128:
129: if File.exists?(spec_file)
130: spec = YAML.load(File.read(spec_file))
131: else
132: spec = nil
133: end
134:
135: if spec && spec.require_path
136: spec.require_path.each { |rp| $:.insert(0, File.expand_path(File.join(file, rp))) }
137: else
138: # puts "File.expand_path(file): #{File.expand_path(file)}"
139: # $:.insert(0, File.expand_path(file))
140: end
141:
142: found_local_gem = true
143: break
144: end
145: end
146:
147: # if After going through the vendor/gems folder and we still didn't find
148: # any frozen gem that matched the criteria, then call the system's gem loader
149: if !found_local_gem
150: # puts "Loading installed gem: #{gem_name}"
151: old_gem(gem_name, *version_requirements)
152: end
153: end
Returns Mack::Utils::GemManager
# File lib/mack/core_extensions/kernel.rb, line 30
30: def require_gems
31: yield Mack::Utils::GemManager.instance
32: end
Returns Mack::Portlets::Manager
# File lib/mack/core_extensions/kernel.rb, line 13
13: def require_portlets
14: yield Mack::Portlet::Manager.instance
15: end
Returns an Array of gems required by the Mack::Utils::GemManager
# File lib/mack/core_extensions/kernel.rb, line 35
35: def required_gem_list
36: Mack::Utils::GemManager.instance.required_gem_list
37: end