Class: Nandi::IndexGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Formatting
Defined in:
lib/generators/nandi/index/index_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Formatting

#format_value, included

Instance Attribute Details

#add_index_nameObject (readonly)

Returns the value of attribute add_index_name.



16
17
18
# File 'lib/generators/nandi/index/index_generator.rb', line 16

def add_index_name
  @add_index_name
end

#columnsObject (readonly)

Returns the value of attribute columns.



16
17
18
# File 'lib/generators/nandi/index/index_generator.rb', line 16

def columns
  @columns
end

#index_nameObject (readonly)

Returns the value of attribute index_name.



16
17
18
# File 'lib/generators/nandi/index/index_generator.rb', line 16

def index_name
  @index_name
end

#tableObject (readonly)

Returns the value of attribute table.



16
17
18
# File 'lib/generators/nandi/index/index_generator.rb', line 16

def table
  @table
end

Instance Method Details

#add_indexObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/nandi/index/index_generator.rb', line 18

def add_index
  tables_list = tables.split(",")
  @columns = columns.split(",")

  tables_list.each_with_index do |table, idx|
    next if table.empty?

    @table = table.to_sym

    @add_index_name = "add_index_on_#{columns.join('_')}_to_#{table}"
    @index_name = (
      override_index_name || "idx_#{table}_on_#{columns.join('_')}"
    ).to_sym

    template(
      "add_index.rb",
      "#{base_path}/#{timestamp(idx)}_#{add_index_name}.rb",
    )
  end
end