Class: Yiffspace::FixerGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/yiffspace/fixer/fixer_generator.rb

Overview

Scaffolds a new db/fixes/*.rb script for YiffSpace::FixTracker (see rake fixes:list).

--steps N splits the fix into N ordered steps sharing an id, each one a copy of the generic fixer.rb template. A host app can instead define a YiffSpace::FixerTemplate subclass (see that class) to control both the step count and each step's file content, auto-discovered from YiffSpace.config.fixer_templates_path - reachable here with --template <name>/-t <name>, or with the template's own shortname flag if it registered one (e.g. -e).

Instance Method Summary collapse

Instance Method Details

#create_fixerObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/generators/yiffspace/fixer/fixer_generator.rb', line 28

def create_fixer
  content_blocks = resolve_content_blocks

  id = Dir[File.join(destination_root, "db/fixes/*.rb")].map { |f| File.basename(f, ".rb").split("_").first.to_i }.max.to_i + 1

  if content_blocks.size == 1
    create_fixer_file("db/fixes/#{id}_#{file_name}.rb", content_blocks.first)
  else
    content_blocks.each_with_index { |block, index| create_fixer_file("db/fixes/#{id}_#{index + 1}_#{file_name}.rb", block) }
  end
end