module Stockboy::TemplateFile

Find and read template files from the configured load paths

Public Class Methods

find(filename) click to toggle source

Find a named DSL template from configuration.template_load_paths

@param [String] filename Template basename to be searched from load paths @return [String] The full path to the first matched filename if found

# 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) click to toggle source

Read template file contents for defining a new job

@param [String] template_name

The file basename of a predefined template

@return [String] Job template DSL or nil if nothing is found

# 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) click to toggle source

Potential locations for finding a template file

@param [String] filename Template basename @return [Array] filename on each possible load path

# 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