class SignatureGenerator::Processor
Constants
- MAX_RETRY
Attributes
context[R]
max_retry[RW]
results[R]
Public Class Methods
new(context: {}, max_retry: MAX_RETRY)
click to toggle source
# File lib/signature_generator/processor.rb, line 14 def initialize(context: {}, max_retry: MAX_RETRY) self.context = context self.max_retry = max_retry end
Public Instance Methods
context=(context)
click to toggle source
# File lib/signature_generator/processor.rb, line 42 def context=(context) raise SignatureGenerator::Error, 'Context cannot be nil' if context.nil? @context = case context when Hash SignatureGenerator::Context.new context when SignatureGenerator::Context context end end
transform(template, context = self.context)
click to toggle source
# File lib/signature_generator/processor.rb, line 19 def transform(template, context = self.context) counters = {} begin if config[:'inline-images'] template = SignatureGenerator::Inliner.new(template).inlined end @results = ERB.new(template, nil, '-').result(context_as_binding context) rescue NameError => e missing_var = e.name counters[missing_var] ||= 0 counters[missing_var] += 1 debug_msg = "Variable not provided: #{missing_var} (attempt ##{counters[missing_var]})" logger.debug debug_msg if counters[missing_var] > max_retry logger.error 'Maximum retry number exceeded. Aborting !' raise e end user_input = get_user_input("Please enter value for '#{missing_var}' > ").gsub /\\n/, '<br>' context[missing_var] = user_input unless user_input.nil? or user_input.empty? retry end end
Private Instance Methods
context_as_binding(context)
click to toggle source
# File lib/signature_generator/processor.rb, line 54 def context_as_binding(context) context.instance_eval do binding end end