class Planter::Generators::AdapterGenerator
Rails generator that creates a custom adapter stub and configures Planter to use it.
Public Instance Methods
Source
# File lib/generators/planter/adapter_generator.rb, line 15 def generate_adapter create_file adapter_path, <<~RUBY # frozen_string_literal: true module Planter module Adapters ## # Custom table-oriented adapter for Planter. class #{adapter_class_name} ## # Create a record unless one already exists. # # @param [Planter::SeedContext] context seeder configuration # # @param [Hash] lookup_attributes attributes used to find the record # # @param [Hash] create_attributes additional attributes used only when # creating a new record # # @return [Object] def create_record(context:, lookup_attributes:, create_attributes:) raise NotImplementedError, "\#{self.class} must implement #create_record" end ## # Return the parent ids to use when seeding child records. # # @param [Planter::SeedContext] context seeder configuration # # @return [Array] def parent_ids(context:) raise NotImplementedError, "\#{self.class} must implement #parent_ids" end ## # Return the foreign key used to assign a parent id on a child record. # # @param [Planter::SeedContext] context seeder configuration # # @return [String, Symbol] def foreign_key(context:) raise NotImplementedError, "\#{self.class} must implement #foreign_key" end ## # Return native columns or fields for the table being seeded. # # @param [Planter::SeedContext] context seeder configuration # # @return [Array<String>] def table_columns(context:) raise NotImplementedError, "\#{self.class} must implement #table_columns" end ## # Return table or collection names that can have seeders generated. # # @return [Array<String>] def table_names raise NotImplementedError, "\#{self.class} must implement #table_names" end end end end RUBY end
Create a custom adapter file with the required adapter API.
Source
# File lib/generators/planter/adapter_generator.rb, line 84 def update_initializer contents = ::File.read(initializer_full_path) contents = replace_or_insert_adapter_require(contents) contents = replace_or_insert_adapter_config(contents) ::File.write(initializer_full_path, contents) end
Update the Planter initializer to require and configure the new adapter.