module Tengine::Support::YamlWithErb

Constants

ERB_EXTNAME

Public Class Methods

extended(klass) click to toggle source
# File lib/tengine/support/yaml_with_erb.rb, line 11
def extended(klass)
  return if klass.respond_to?(:load_file_without_erb)
  klass.instance_eval do
    alias :load_file_without_erb :load_file

    def load_file(filepath)
      if File.extname(filepath) == ERB_EXTNAME
        load_file_with_erb(filepath)
      else
        load_file_without_erb(filepath)
      end
    end

  end
end
load_file(filepath) click to toggle source
# File lib/tengine/support/yaml_with_erb.rb, line 16
def load_file(filepath)
  if File.extname(filepath) == ERB_EXTNAME
    load_file_with_erb(filepath)
  else
    load_file_without_erb(filepath)
  end
end

Public Instance Methods

load_file_with_erb(filepath) click to toggle source
# File lib/tengine/support/yaml_with_erb.rb, line 28
def load_file_with_erb(filepath)
  erb = ERB.new(IO.read(filepath))
  erb.filename = filepath
  text = erb.result
  YAML.load(text)
end