class ActiveSupport::CodeGenerator
:nodoc:
def batch(owner, path, line)
def batch(owner, path, line) if owner.is_a?(CodeGenerator) yield owner else instance = new(owner, path, line) result = yield instance instance.execute result end end
def class_eval
def class_eval yield @sources end
def define_cached_method(canonical_name, namespace:, as: nil, &block)
def define_cached_method(canonical_name, namespace:, as: nil, &block) @namespaces[namespace].define_cached_method(canonical_name, as: as, &block) end
def execute
def execute @namespaces.each_value do |method_set| method_set.apply(@owner, @path, @line - 1) end unless @sources.empty? @owner.class_eval("# frozen_string_literal: true\n" + @sources.join(";"), @path, @line - 1) end end
def initialize(owner, path, line)
def initialize(owner, path, line) @owner = owner @path = path @line = line @namespaces = Hash.new { |h, k| h[k] = MethodSet.new(k) } @sources = [] end