class RgGen::Core::InputBase::Feature
Attributes
builders[R]
input_matcher[R]
post_builders[R]
printables[R]
verifiers[R]
match_data[R]
match_index[R]
position[R]
Public Class Methods
active_feature?()
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 44 def active_feature? !passive_feature? end
build(&block)
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 30 def build(&block) @builders ||= [] @builders << block end
ignore_empty_value(value = nil)
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 21 def ignore_empty_value(value = nil) @ignore_empty_value = value unless value.nil? @ignore_empty_value end
ignore_empty_value?()
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 26 def ignore_empty_value? @ignore_empty_value.nil? || @ignore_empty_value end
inherited(subclass)
click to toggle source
Calls superclass method
# File lib/rggen/core/input_base/feature.rb, line 73 def inherited(subclass) super export_instance_variable(:@properties, subclass, &:dup) export_instance_variable(:@ignore_empty_value, subclass) export_instance_variable(:@builders, subclass, &:dup) export_instance_variable(:@post_builders, subclass, &:dup) export_instance_variable(:@input_matcher, subclass) export_instance_variable(:@printables, subclass, &:dup) export_verifiers(subclass) if @verifiers end
input_pattern(pattern_or_patterns, **options, &converter)
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 52 def input_pattern(pattern_or_patterns, **options, &converter) @input_matcher = InputMatcher.new(pattern_or_patterns, **options, &converter) end
passive_feature?()
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 48 def passive_feature? builders.nil? end
post_build(&block)
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 37 def post_build(&block) @post_builders ||= [] @post_builders << block end
printable(name, &body)
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 66 def printable(name, &body) @printables ||= {} @printables[name] = body end
properties()
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 17 def properties @properties ||= [] end
property(name, **options, &body)
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 10 def property(name, **options, &body) Property.define(self, name, **options, &body) properties.include?(name) || properties << name end
Also aliased as: field
verify(scope, &block)
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 59 def verify(scope, &block) @verifiers ||= {} (@verifiers[scope] ||= []) << create_verifier(&block) end
Private Class Methods
create_verifier(&body)
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 86 def create_verifier(&body) Verifier.new(&body) end
export_verifiers(subclass)
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 90 def export_verifiers(subclass) subclass.instance_variable_set( :@verifiers, @verifiers.transform_values(&:dup) ) end
Public Instance Methods
build(*args)
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 102 def build(*args) self.class.builders && do_build(args) end
inspect()
click to toggle source
Calls superclass method
RgGen::Core::Base::Feature#inspect
# File lib/rggen/core/input_base/feature.rb, line 126 def inspect printable_values = printables&.map { |name, value| "#{name}: #{value.inspect}" } (printable_values && "#{super}[#{printable_values.join(', ')}]") || super end
post_build()
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 106 def post_build self.class.post_builders&.each do |post_builder| instance_exec(&post_builder) end end
printable?()
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 122 def printable? !helper.printables.nil? end
printables()
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 116 def printables helper .printables &.map { |name, body| [name, printable(name, &body)] } end
verify(scope)
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 112 def verify(scope) verified?(scope) || do_verify(scope) end
Private Instance Methods
do_build(args)
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 134 def do_build(args) @position = args.last.position value = args.last.value match_automatically? && match_pattern(value) Array(self.class.builders) .each { |builder| instance_exec(*args[0..-2], value, &builder) } end
do_verify(scope)
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 165 def do_verify(scope) self.class.verifiers&.[](scope) &.each { |verifier| verifier.verify(self) } (@verified ||= {})[scope] = true end
match_automatically?()
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 144 def match_automatically? matcher = self.class.input_matcher matcher&.match_automatically? end
match_pattern(rhs)
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 149 def match_pattern(rhs) matcher = self.class.input_matcher @match_data, @match_index = matcher&.match(rhs) end
pattern_matched?()
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 157 def pattern_matched? !match_data.nil? end
printable(name, &body)
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 171 def printable(name, &body) block_given? ? instance_exec(&body) : __send__(name) end
verified?(scope)
click to toggle source
# File lib/rggen/core/input_base/feature.rb, line 161 def verified?(scope) @verified && @verified[scope] end