class DiceBag::AvailableTemplates
Public Class Methods
all(gem_names = [])
click to toggle source
# File lib/dice_bag/available_templates.rb, line 43 def all(gem_names = []) # all the classes than inherit from us in the ruby runtime available_templates = [] template_checkers.each do |template_checker| checker = template_checker.new next if !gem_names.empty? && !checker_within_given_gems?(checker, gem_names) location = checker.templates_location checker.templates.each do |template, save_as| available_templates.push(DefaultTemplateFile.new(template, location, save_as)) end end available_templates end
checker_within_given_gems?(checker, gem_names)
click to toggle source
# File lib/dice_bag/available_templates.rb, line 26 def checker_within_given_gems?(checker, gem_names) checker_file = checker.method(:templates).source_location[0] gem_specs.each do |name, location| return true if checker_file.start_with?(location) && gem_names.include?(name) end false end
gem_specs()
click to toggle source
# File lib/dice_bag/available_templates.rb, line 18 def gem_specs @gem_specs ||= begin Gem::Specification.sort.each_with_object({}) do |spec, hsh| hsh[spec.name] = spec.full_gem_path end end end
inherited(base)
click to toggle source
# File lib/dice_bag/available_templates.rb, line 39 def inherited(base) template_checkers << base end
template_checkers()
click to toggle source
# File lib/dice_bag/available_templates.rb, line 35 def template_checkers @template_checkers ||= [] end
template_filename_for(filename)
click to toggle source
# File lib/dice_bag/available_templates.rb, line 59 def template_filename_for(filename) all.find { |template| template.filename.include?(filename) } end
Public Instance Methods
templates_location()
click to toggle source
By default the final location for any template will be the config directory. If any template 'plugin' wants to overwrite the directory where its template will be written it needs to overwrite this method and return a string with the new location as relative path inside the project.
# File lib/dice_bag/available_templates.rb, line 13 def templates_location "config" end