Module: Stockboy::TemplateFile

Defined in:
lib/stockboy/template_file.rb

Overview

Find and read template files from the configured load paths

Class Method Summary collapse

Class Method Details

.find(filename) ⇒ String

Find a named DSL template from configuration.template_load_paths



27
28
29
30
# File 'lib/stockboy/template_file.rb', line 27

def self.find(filename)
  sources = template_file_paths(filename)
  Dir.glob(sources).first
end

.read(template_name) ⇒ String

Read template file contents for defining a new job



15
16
17
18
19
20
# File 'lib/stockboy/template_file.rb', line 15

def self.read(template_name)
  return template_name.read if template_name.is_a? File
  return unless path = find(template_name)

  File.read(path)
end

.template_file_paths(filename) ⇒ Array

Potential locations for finding a template file



37
38
39
40
41
# File 'lib/stockboy/template_file.rb', line 37

def self.template_file_paths(filename)
  filename = "#{filename}.rb" unless filename =~ /\.rb$/
  load_paths = Array(Stockboy.configuration.template_load_paths)
  load_paths.map { |d| File.join(d, filename) }
end