Sha256: af6ee570d1c41d0483b2f3040b0b62045f14aced1026e6fc895b14e0cb64325d

Contents?: true

Size: 733 Bytes

Versions: 29

Compression:

Stored size: 733 Bytes

Contents

require 'tengine/support'

require 'yaml'
require 'erb'

module Tengine::Support::YamlWithErb

  ERB_EXTNAME = ".erb".freeze

  class << self
    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
  end

  def load_file_with_erb(filepath)
    erb = ERB.new(IO.read(filepath))
    erb.filename = filepath
    text = erb.result
    YAML.load(text)
  end
end

YAML.extend(Tengine::Support::YamlWithErb)

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
tengine_support-1.2.2 lib/tengine/support/yaml_with_erb.rb
tengine_support-1.2.1 lib/tengine/support/yaml_with_erb.rb
tengine_support-1.2.0 lib/tengine/support/yaml_with_erb.rb
tengine_support-1.1.0 lib/tengine/support/yaml_with_erb.rb
tengine_support-0.3.27 lib/tengine/support/yaml_with_erb.rb
tengine_support-0.3.26 lib/tengine/support/yaml_with_erb.rb
tengine_support-0.3.25 lib/tengine/support/yaml_with_erb.rb
tengine_support-0.3.24 lib/tengine/support/yaml_with_erb.rb
tengine_support-0.3.22 lib/tengine/support/yaml_with_erb.rb
tengine_support-0.3.21 lib/tengine/support/yaml_with_erb.rb
tengine_support-0.3.20 lib/tengine/support/yaml_with_erb.rb
tengine_support-0.3.19 lib/tengine/support/yaml_with_erb.rb
tengine_support-0.3.18 lib/tengine/support/yaml_with_erb.rb
tengine_support-0.3.17 lib/tengine/support/yaml_with_erb.rb
tengine_support-0.3.16 lib/tengine/support/yaml_with_erb.rb
tengine_support-0.3.15 lib/tengine/support/yaml_with_erb.rb
tengine_support-0.3.14 lib/tengine/support/yaml_with_erb.rb
tengine_support-0.3.13 lib/tengine/support/yaml_with_erb.rb
tengine_support-0.3.12 lib/tengine/support/yaml_with_erb.rb
tengine_support-0.3.11 lib/tengine/support/yaml_with_erb.rb