Module: Kernel

Defined in:
lib/mack/assets/assets_mgr.rb,
lib/mack/core_extensions/kernel.rb,
lib/mack/initialization/boot_loader.rb

Defined Under Namespace

Classes: DeprecatedRegistryList

Instance Method Summary collapse

Instance Method Details

#alias_deprecated_method(deprecated_method, new_method, version_deprecrated = nil, version_to_be_removed = nil) ⇒ Object

Aliases the deprecated method to the new method and logs a warning.



14
15
16
17
18
19
20
21
# File 'lib/mack/core_extensions/kernel.rb', line 14

def alias_deprecated_method(deprecated_method, new_method, version_deprecrated = nil, version_to_be_removed = nil)
  eval %{
    def #{deprecated_method}(*args)
      deprecate_method(:#{deprecated_method}, :#{new_method}, "#{version_deprecrated}", "#{version_to_be_removed}")
      #{new_method}(*args)
    end
  }
end

#assets_mgrObject

Return the instance of the AssetManager class.



162
163
164
# File 'lib/mack/assets/assets_mgr.rb', line 162

def assets_mgr
  return Mack::Assets::Manager.instance
end

#boot_load(name, *dependencies, &block) ⇒ Object



3
4
5
# File 'lib/mack/initialization/boot_loader.rb', line 3

def boot_load(name, *dependencies, &block)
  Mack::BootLoader.instance.add(name, *dependencies, &block)
end

#deprecate_method(deprecated_method, new_method = nil, version_deprecrated = nil, version_to_be_removed = nil) ⇒ Object

Logs a warning that a method has been deprecated. Warnings will only get logged once.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mack/core_extensions/kernel.rb', line 24

def deprecate_method(deprecated_method, new_method = nil, version_deprecrated = nil, version_to_be_removed = nil)
  message = "DEPRECATED: '#{deprecated_method}'."
  if new_method
    message << " Please use '#{new_method}' instead."
  end
  if version_deprecrated
    message << " Deprecated in version: '#{version_deprecrated}'."
    if version_to_be_removed.nil?
      version_to_be_removed = ">=#{version_deprecrated.succ}"
    end
  end
  if version_to_be_removed
    message << " To be removed in version: '#{version_to_be_removed}'."
  end
  unless Kernel::DeprecatedRegistryList.registered_items.include?(message)
    Mack.logger.warn(message)
    Kernel::DeprecatedRegistryList.add(message)
  end
end

#gem(gem_name, *version_requirements) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/mack/core_extensions/kernel.rb', line 49

def gem(gem_name, *version_requirements)
  vendor_path = File.join(Mack.root, 'vendor')
  gem_path = File.join(vendor_path, 'gems')
  
  # try to normalize the version requirement string
  ver = version_requirements.to_s.strip
  ver = "> 0.0.0" if ver == nil or ver.empty?
  # if the version string starts with number, then prepend = to it (since the developer wants an exact match)
  ver = "= " + ver if ver[0,1] != '=' and ver[0,1] != '>' and ver[0,1] != '<'
  
  num = ver.match(/\d.+/).to_s
  op  = ver.delete(num).strip
  op  += "=" if op == '=' 
  
  found_local_gem = false
  
  Dir.glob(File.join(gem_path, "#{gem_name}*")).each_with_index do |file, i|
    # all frozen gem has the pattern [gem_name]-[version]
    next if !file.include?'-'
  
    # make sure we're not loading gem with almost the same name, e.g. "#{gem_name}-foo_bar-0.89.1"
    file_gem_name = file.match(/\D*-/).to_s
    next if !file.starts_with?(file_gem_name)
    
    # find the version number from the file name
    file_ver = file.match(/\d.+/).to_s
    
    # generate number comparison string that we can evaluate, to make sure that we
    # pick the correct gem based on the requested version requirements
    comparison = "'#{file_ver}' #{op} '#{num}'"  # e.g.: "'0.8.0' > '0.0.0'"
    
    # if we find the match (i.e. the comparison string checks out) then
    # read the frozen spec file in that directory (so we can see what the require path is)
    # and prepend the new require path(s) to the global search path.
    # If we didn't find it, then continue to look (obviously)
    if eval(comparison)           
      spec_file = File.join(file, 'spec.yaml')
      
      if File.exists?(spec_file)
        spec = YAML.load(File.read(spec_file))
      else
        spec = nil
      end
      
      if spec and spec.require_path
        spec.require_path.each { |rp| $:.insert(0, File.expand_path(File.join(file, rp))) }
      else
        $:.insert(0, File.expand_path(file))
      end

      found_local_gem = true
      break
    end
  end 

  # if After going through the vendor/gems folder and we still didn't find
  # any frozen gem that matched the criteria, then call the system's gem loader
  if !found_local_gem
    # puts "Loading installed gem: #{gem_name}"
    old_gem(gem_name, *version_requirements)
  end
end

#require_gems {|Mack::Utils::GemManager.instance| ... } ⇒ Object

Returns Mack::Utils::GemManager

Yields:



4
5
6
# File 'lib/mack/core_extensions/kernel.rb', line 4

def require_gems
  yield Mack::Utils::GemManager.instance
end

#required_gem_listObject

Returns an Array of gems required by the Mack::Utils::GemManager



9
10
11
# File 'lib/mack/core_extensions/kernel.rb', line 9

def required_gem_list
  Mack::Utils::GemManager.instance.required_gem_list
end