Class: YiffSpace::FixerTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/yiffspace/fixer_template.rb

Overview

Base class for a bin/rails generate yiffspace:fixer template, auto-discovered from *.rb files in YiffSpace.config.fixer_templates_path (default db/fixer_templates) - no explicit registration needed, just define a subclass:

class ElasticsearchTemplate < YiffSpace::FixerTemplate
short("e")

step { "..." }
step { "..." }
end

The template's name comes from the class name with a trailing "Template" dropped and kebab-cased (ElasticsearchTemplate -> "elasticsearch", OpenSearchTemplate -> "open-search"), reachable as --template <name> (see Yiffspace::FixerGenerator). Its step count is the number of step blocks - each one's return value becomes that step's fix file content, instead of the generic fixer.rb template a plain --steps N copies for every step.

Class Method Summary collapse

Class Method Details

.short(value = nil) ⇒ Object

Optional - a template is always reachable via --template <name>, a registered shortname flag (e.g. -e) is just a convenient alias for it.



24
25
26
27
# File 'lib/yiffspace/fixer_template.rb', line 24

def short(value = nil)
  @short = value.to_s.delete_prefix("-") unless value.nil?
  @short
end

.step(&block) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
# File 'lib/yiffspace/fixer_template.rb', line 29

def step(&block)
  raise(ArgumentError, "#{name}.step requires a block") unless block

  steps << block
end

.stepsObject



35
36
37
# File 'lib/yiffspace/fixer_template.rb', line 35

def steps
  @steps ||= []
end

.template_nameObject



39
40
41
# File 'lib/yiffspace/fixer_template.rb', line 39

def template_name
  name.demodulize.delete_suffix("Template").underscore.dasherize
end