Class: DiceBag::AvailableTemplates
- Inherits:
-
Object
- Object
- DiceBag::AvailableTemplates
- Defined in:
- lib/dice_bag/available_templates.rb
Direct Known Subclasses
Class Method Summary collapse
- .all(gem_names = []) ⇒ Object
- .checker_within_given_gems?(checker, gem_names) ⇒ Boolean
- .gem_specs ⇒ Object
- .inherited(base) ⇒ Object
- .template_checkers ⇒ Object
- .template_filename_for(filename) ⇒ Object
Instance Method Summary collapse
-
#templates_location ⇒ Object
By default the final location for any template will be the config directory.
Class Method Details
.all(gem_names = []) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# 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| available_templates.push( DefaultTemplateFile.new(template, location) ) end end available_templates end |
.checker_within_given_gems?(checker, gem_names) ⇒ Boolean
27 28 29 30 31 32 33 |
# File 'lib/dice_bag/available_templates.rb', line 27 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 ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/dice_bag/available_templates.rb', line 19 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) ⇒ Object
39 40 41 |
# File 'lib/dice_bag/available_templates.rb', line 39 def inherited(base) template_checkers << base end |
.template_checkers ⇒ Object
35 36 37 |
# File 'lib/dice_bag/available_templates.rb', line 35 def template_checkers @template_checkers ||= [] end |
.template_filename_for(filename) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/dice_bag/available_templates.rb', line 58 def template_filename_for(filename) self.all.each do |template| if template.filename.include? filename return template.file end end end |
Instance Method Details
#templates_location ⇒ Object
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.
13 14 15 |
# File 'lib/dice_bag/available_templates.rb', line 13 def templates_location 'config' end |