Skip to content

Commit

Permalink
update load template gem policy: $LOAD_PATH first, then latest gems
Browse files Browse the repository at this point in the history
  • Loading branch information
teohm committed Jun 12, 2012
1 parent 2bf47cd commit 0c81519
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/captify/template.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
module Captify
class Template

def self.find_files_in_load_path(glob)
$LOAD_PATH.map { |load_path|
Dir["#{File.expand_path glob, load_path}#{Gem.suffix_pattern}"]
}.flatten.select { |file| File.file? file.untaint }
end

def self.find_files_in_latest_gems(glob, prelease=false)
Gem::Specification.latest_specs(:prelease => prelease).map { |spec|
spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}")
}.flatten
end

def self.find_latest_files(glob, check_load_path=true)
files = []
files = find_files_in_load_path(glob) if check_load_path
files.concat find_files_in_latest_gems(glob)
return files
end

def self.load_all
Gem.find_files('captify_template').each do |path|
find_latest_files('captify_template').each do |path|
load path if File.exist? path
end
end
Expand Down

0 comments on commit 0c81519

Please sign in to comment.