Module: DeclareSchema::Support::EvalTemplate

Defined in:
lib/generators/declare_schema/support/eval_template.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/generators/declare_schema/support/eval_template.rb', line 7

def included(base)
  base.class_eval do
    private

    def eval_template(template_name)
      source = File.expand_path(find_in_source_paths(template_name))
      erb = ERB.new(::File.read(source).force_encoding(Encoding::UTF_8), trim_mode: '>')
      erb.filename = source
      begin
        erb.result(binding)
      rescue Exception => ex
        raise ex.class, <<~EOS
          #{ex.message}
          #{erb.src}
            #{ex.backtrace.join("\n  ")}
        EOS
      end
    end
  end
end