Class: Localtower::Generators::ServiceObjects::InsertIndexes
- Inherits:
-
Object
- Object
- Localtower::Generators::ServiceObjects::InsertIndexes
- Defined in:
- lib/localtower/generators/service_objects/insert_indexes.rb
Constant Summary collapse
- USING =
[ { label: 'default', name: 'default', example: 'using: :btree' }, { name: 'hash', example: 'using: :hash' }, { name: 'gin', example: 'using: :gin' }, { name: 'gist', example: 'using: :gist' }, { name: 'spgist', example: 'using: :spgist' }, { name: 'brin', example: 'using: :brin' }, { name: 'bloom', example: 'using: :bloom' } ]
- UNIQUE =
[ false, true ]
- ALGO =
%w[ concurrently ]
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(attributes) ⇒ InsertIndexes
constructor
A new instance of InsertIndexes.
Constructor Details
#initialize(attributes) ⇒ InsertIndexes
Returns a new instance of InsertIndexes.
46 47 48 |
# File 'lib/localtower/generators/service_objects/insert_indexes.rb', line 46 def initialize(attributes) @attributes = attributes end |
Instance Method Details
#call ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/localtower/generators/service_objects/insert_indexes.rb', line 50 def call attributes.each do |attribute| attribute.each do |attr_key, | line_str_original = File.read(Localtower::Tools.last_migration_pending).match(/((.*)add_index :(.*), :#{attr_key})/)[0] line_str = line_str_original.clone line_str = inser_using(line_str, ) line_str = inser_algorithm(line_str, ) line_str = inser_unique(line_str, ) content = File.read(Localtower::Tools.last_migration_pending).gsub(line_str_original, line_str) content = add_disable_ddl_transaction(content, ) File.write(Localtower::Tools.last_migration_pending, content) end end end |