class RgGen::Core::OutputBase::Feature

Attributes

builders[R]
file_writer[R]
pre_builders[R]

Public Class Methods

code_generators() click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 14
def code_generators
  @code_generators ||= {}
end
copy_code_generators(subclass) click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 88
def copy_code_generators(subclass)
  @code_generators&.each do |phase, generator|
    subclass.code_generators[phase] = generator.copy
  end
end
exported_methods() click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 25
def exported_methods
  @exported_methods ||= []
end
inherited(subclass) click to toggle source
Calls superclass method
# File lib/rggen/core/output_base/feature.rb, line 78
def inherited(subclass)
  super
  export_instance_variable(:@pre_builders, subclass, &:dup)
  export_instance_variable(:@builders, subclass, &:dup)
  export_instance_variable(:@template_engine, subclass)
  export_instance_variable(:@file_writer, subclass)
  export_instance_variable(:@exported_methods, subclass, &:dup)
  copy_code_generators(subclass)
end
template_engine(engine = nil) click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 18
def template_engine(engine = nil)
  @template_engine = engine.instance if engine
  @template_engine
end

Private Class Methods

build(&body) click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 36
def build(&body)
  @builders ||= []
  @builders << body
end
export(*methods) click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 69
def export(*methods)
  methods.each do |method|
    exported_methods.include?(method) ||
      (exported_methods << method)
  end
end
extract_template_path(options) click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 60
def extract_template_path(options)
  path = options[:from_template]
  path.equal?(true) ? nil : path
end
pre_build(&body) click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 31
def pre_build(&body)
  @pre_builders ||= []
  @pre_builders << body
end
register_code_generator(phase, kind, **options, &body) click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 47
def register_code_generator(phase, kind, **options, &body)
  block =
    if options[:from_template]
      path = extract_template_path(options)
      location = caller_locations(2, 1).first
      -> { process_template(path, location) }
    else
      body
    end
  (code_generators[phase] ||= CodeGenerator.new)
    .register(kind, &block)
end
write_file(file_name_pattern, &body) click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 65
def write_file(file_name_pattern, &body)
  @file_writer = FileWriter.new(file_name_pattern, &body)
end

Public Instance Methods

build() click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 105
def build
  helper
    .builders
    &.each { |body| instance_exec(&body) }
end
export(*methods) click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 111
def export(*methods)
  methods.each do |method|
    unless exported_methods(:class).include?(method) ||
           exported_methods(:object).include?(method)
      exported_methods(:object) << method
    end
  end
end
exported_methods(scope) click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 120
def exported_methods(scope)
  if scope == :class
    self.class.exported_methods
  else
    @exported_methods ||= []
  end
end
generate_code(code, phase, kind) click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 128
def generate_code(code, phase, kind)
  generator = self.class.code_generators[phase]
  generator&.generate(self, code, kind)
end
post_initialize() click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 95
def post_initialize
  define_layer_methods
end
pre_build() click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 99
def pre_build
  helper
    .pre_builders
    &.each { |body| instance_exec(&body) }
end
write_file(directory = nil) click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 133
def write_file(directory = nil)
  file_writer = self.class.file_writer
  file_writer&.write_file(self, directory)
end

Private Instance Methods

configuration() click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 140
def configuration
  component.configuration
end
process_template(path = nil, caller_location = nil) click to toggle source
# File lib/rggen/core/output_base/feature.rb, line 144
def process_template(path = nil, caller_location = nil)
  caller_location ||= caller_locations(1, 1).first
  template_engine = self.class.template_engine
  template_engine.process_template(self, path, caller_location)
end