class Dagger::Generator
Abstract super class for default value generators. Stores the Context
on initialization, and provides private helper methods to concrete subclasses.
Context
key access: :call-seq:
dictionary => Hash-like with current key lookup dictionary.
Context
value update: :call-seq:
update(key: value, ...)
Stop the processing of current rule chain: :call-seq:
stop
Wrap non-enumerable objects in an Array
:call-seq:
enumerable(value) => value || [value]
Concrete subclasses must implement: :call-seq:
process(arg, &->(value))
arg
-
Value for current method in the
rule_chain
value
-
If a value was found it should be
yield
:ed
Public Class Methods
[](context, arg, &result_yielder)
click to toggle source
# File lib/dagger/generator.rb, line 35 def self.[](context, arg, &result_yielder) new(context).process(arg, &result_yielder) end
new(context)
click to toggle source
# File lib/dagger/generator.rb, line 39 def initialize(context) @context = context end
Private Instance Methods
array(value) → value || [value]
click to toggle source
Make an array of a value unless it is already an array
# File lib/dagger/generator.rb, line 67 def array(value) value.respond_to?(:to_ary) ? value : [value] end
format(string)
click to toggle source
Format a string
with values from a dictionary
# File lib/dagger/generator.rb, line 75 def format_string(string) hash = Hash.new do |_, key| result = @context.dictionary[key] next result unless result.nil? return nil end format(string, hash) end
stop
click to toggle source
Stop processing the current rule chain
# File lib/dagger/generator.rb, line 51 def stop throw @context.stop end
update(key: value, ...)
click to toggle source
Update context attributes with new values
# File lib/dagger/generator.rb, line 59 def update(**kwargs) kwargs.each { |key, value| @context[key] = value } end