Class: YiffSpace::Configuration::FixerTemplates

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/yiffspace/configuration/fixer_templates.rb

Overview

Named presets for bin/rails generate yiffspace:fixer, so --template <name> (or a registered shortname flag) can stand in for --steps N. Populated two ways:

  • Automatically, from YiffSpace::FixerTemplate subclasses found in YiffSpace.config.fixer_templates_path (the common case - see FixerTemplate).
  • Manually, via #register, for a preset that just needs a step count and no per-step content (every step falls back to the generic fixer.rb template).

See YiffSpace::Configuration#fixer_templates and Yiffspace::FixerGenerator.

Defined Under Namespace

Classes: Template

Constant Summary collapse

RESERVED_SHORTS =

-t is yiffspace:fixer's own --template flag; -f/-p/-q/-s are Rails::Generators::Base's built-in runtime options (--force/--pretend/--quiet/--skip).

%w[t f p q s].freeze

Instance Method Summary collapse

Methods included from Extensions::Enumerable::Parallel

#parallel_each, #parallel_map

Constructor Details

#initializeFixerTemplates

Returns a new instance of FixerTemplates.



27
28
29
30
# File 'lib/yiffspace/configuration/fixer_templates.rb', line 27

def initialize
  @templates = {}
  @discovered = false
end

Instance Method Details

#[](name) ⇒ Object



40
41
42
43
# File 'lib/yiffspace/configuration/fixer_templates.rb', line 40

def [](name)
  discover!
  @templates[name.to_s]
end

#eachObject



45
46
47
48
# File 'lib/yiffspace/configuration/fixer_templates.rb', line 45

def each(&)
  discover!
  @templates.each_value(&)
end

#register(name, steps:, short: nil) ⇒ Object

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

Raises:

  • (ArgumentError)


34
35
36
37
38
# File 'lib/yiffspace/configuration/fixer_templates.rb', line 34

def register(name, steps:, short: nil)
  raise(ArgumentError, "steps must be a positive integer, got #{steps.inspect}") unless steps.is_a?(Integer) && steps.positive?

  add(name.to_s, short: short, content_blocks: Array.new(steps))
end