Class: SignatureGenerator::Processor
- Inherits:
-
Object
- Object
- SignatureGenerator::Processor
- Includes:
- EasyAppHelper, EasyAppHelper::Input
- Defined in:
- lib/signature_generator/processor.rb
Constant Summary collapse
- MAX_RETRY =
3
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#max_retry ⇒ Object
Returns the value of attribute max_retry.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#initialize(context: {}, max_retry: MAX_RETRY) ⇒ Processor
constructor
A new instance of Processor.
- #transform(template, context = self.context) ⇒ Object
Constructor Details
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
11 12 13 |
# File 'lib/signature_generator/processor.rb', line 11 def context @context end |
#max_retry ⇒ Object
Returns the value of attribute max_retry.
12 13 14 |
# File 'lib/signature_generator/processor.rb', line 12 def max_retry @max_retry end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
11 12 13 |
# File 'lib/signature_generator/processor.rb', line 11 def results @results end |
Instance Method Details
#transform(template, context = self.context) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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 |