Source: show | on GitHub
# File activemodel/lib/active_model/attribute_methods.rb, line 340 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
# File activemodel/lib/active_model/attribute_methods.rb, line 352 def initialize(owner, path, line) @owner = owner @path = path @line = line @sources = ["# frozen_string_literal: true\n"] @renames = {} end
# File activemodel/lib/active_model/attribute_methods.rb, line 360 def <<(source_line) @sources << source_line end
# File activemodel/lib/active_model/attribute_methods.rb, line 368 def execute @owner.module_eval(@sources.join(";"), @path, @line - 1) @renames.each do |old_name, new_name| @owner.alias_method new_name, old_name @owner.undef_method old_name end end
# File activemodel/lib/active_model/attribute_methods.rb, line 364 def rename_method(old_name, new_name) @renames[old_name] = new_name end