Class: Planter::SeedContext

Inherits:
Object
  • Object
show all
Defined in:
lib/planter/seed_context.rb

Overview

Parameter object carrying normalized seeder configuration into adapters.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name:, seed_method:, csv_name:, parent:, number_of_records:, unique_columns:, erb_trim_mode:, adapter_options: {}) ⇒ SeedContext

Create a new seed context.

Parameters:

  • table_name (String, Symbol)
  • seed_method (String, Symbol, nil)
  • csv_name (String, Symbol)
  • parent (String, Symbol, nil)
  • number_of_records (Integer)
  • unique_columns (Array<Symbol>, nil)
  • erb_trim_mode (String, nil)
  • adapter_options (Hash) (defaults to: {})

    adapter-specific per-seeder options



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/planter/seed_context.rb', line 75

def initialize(
  table_name:,
  seed_method:,
  csv_name:,
  parent:,
  number_of_records:,
  unique_columns:,
  erb_trim_mode:,
  adapter_options: {}
)
  @table_name = table_name.to_s
  @seed_method = seed_method&.intern
  @csv_name = csv_name.to_s
  @parent = parent
  @number_of_records = number_of_records
  @unique_columns = unique_columns
  @erb_trim_mode = erb_trim_mode
  @adapter_options = adapter_options.to_h.transform_keys(&:to_sym)
end

Instance Attribute Details

#adapter_optionsHash (readonly)

Adapter-specific options collected from the seeder.

Adapters may ignore any options they do not support.

Returns:

  • (Hash)


55
56
57
# File 'lib/planter/seed_context.rb', line 55

def adapter_options
  @adapter_options
end

#csv_nameString (readonly)

The CSV seed file name without an extension.

Returns:

  • (String)


23
24
25
# File 'lib/planter/seed_context.rb', line 23

def csv_name
  @csv_name
end

#erb_trim_modeString? (readonly)

The ERB trim mode used for CSV templates.

Returns:

  • (String, nil)


47
48
49
# File 'lib/planter/seed_context.rb', line 47

def erb_trim_mode
  @erb_trim_mode
end

#number_of_recordsInteger (readonly)

How many times to create each data record.

Returns:

  • (Integer)


35
36
37
# File 'lib/planter/seed_context.rb', line 35

def number_of_records
  @number_of_records
end

#parentString, ... (readonly)

The adapter-defined parent relation.

Returns:

  • (String, Symbol, nil)


29
30
31
# File 'lib/planter/seed_context.rb', line 29

def parent
  @parent
end

#seed_methodSymbol? (readonly)

The configured seeding method.

Returns:

  • (Symbol, nil)


17
18
19
# File 'lib/planter/seed_context.rb', line 17

def seed_method
  @seed_method
end

#table_nameString (readonly)

The table being seeded.

Returns:

  • (String)


11
12
13
# File 'lib/planter/seed_context.rb', line 11

def table_name
  @table_name
end

#unique_columnsArray<Symbol>? (readonly)

Columns used to look up existing records.

Returns:

  • (Array<Symbol>, nil)


41
42
43
# File 'lib/planter/seed_context.rb', line 41

def unique_columns
  @unique_columns
end