class ZanTools::Generatable::Configuration
Public Class Methods
new()
click to toggle source
# File lib/zan_tools/generatable.rb, line 13 def initialize @config = {} end
Public Instance Methods
compile(tmpl)
click to toggle source
# File lib/zan_tools/generatable.rb, line 34 def compile(tmpl) template = ERB.new(tmpl, nil, '-') template.result(binding) rescue StandardError => e raise TemplateError.new("#{e.class} - #{e.message}") end
each(&block)
click to toggle source
# File lib/zan_tools/generatable.rb, line 17 def each(&block) @config.each(&block) end
method_missing(name, *args)
click to toggle source
Calls superclass method
# File lib/zan_tools/generatable.rb, line 21 def method_missing(name, *args) matches = name.match(/([^=]+)(=)?/) # 判断是否为赋值或取值 if !matches.nil? && !matches[2].nil? && args.size == 1 raise "preserved name `#{matches[1]}` is invalid" if respond_to?(matches[1]) @config[matches[1]] = args[0] elsif !matches.nil? && matches[2].nil? && @config.key?(matches[1]) @config[matches[1]] else super end end