class Captify::TemplateLoader

Public Class Methods

new(opts={}) click to toggle source
# File lib/captify/template_loader.rb, line 4
def initialize(opts={})
  @file_name_pattern   = opts.fetch(:file_name_pattern,   'template_bundle')
  @file_suffix_pattern = opts.fetch(:file_suffix_pattern, Gem.suffix_pattern)

  @load_path = opts.fetch(:load_path, $LOAD_PATH)
  @gem_spec  = opts.fetch(:gem_spec,  Gem::Specification)
  @kernel    = opts.fetch(:kernel,    Kernel)
  @file      = opts.fetch(:file,      File)
end

Public Instance Methods

find(template_name) click to toggle source
# File lib/captify/template_loader.rb, line 20
def find(template_name)
  Captify::TemplateRegistrar.instance.find template_name
end
reload!(load_path_only=false) click to toggle source
# File lib/captify/template_loader.rb, line 14
def reload!(load_path_only=false)
  latest_files(@file_name_pattern, load_path_only).each do |path|
    @kernel.load path if @file.exist? path
  end
end

Private Instance Methods

find_latest_gem_files(glob) click to toggle source
# File lib/captify/template_loader.rb, line 39
def find_latest_gem_files(glob)
  @gem_spec.latest_specs.map { |spec|
    spec.matches_for_glob("#{glob}#{@file_suffix_pattern}")
  }.flatten
end
find_load_path_files(glob) click to toggle source
# File lib/captify/template_loader.rb, line 33
def find_load_path_files(glob)
  @load_path.map { |load_path|
    Dir["#{@file.expand_path glob, load_path}#{@file_suffix_pattern}"]
  }.flatten.select { |file| @file.file? file.untaint }
end
latest_files(glob, load_path_only) click to toggle source
# File lib/captify/template_loader.rb, line 26
def latest_files(glob, load_path_only)
  files = []
  files.concat find_load_path_files(glob)
  files.concat find_latest_gem_files(glob) unless load_path_only
  return files
end