class GemBootstrap::SourceGenerator

@api private

Constants

TEMPLATES_DIR

Attributes

templates_dir[R]

@return [String]

Public Class Methods

new(config:, templates_dir: TEMPLATES_DIR) click to toggle source

@param [Configuration] config

# File lib/gem-bootstrap/source_generator.rb, line 12
def initialize(config:, templates_dir: TEMPLATES_DIR)
  @config = config
  @templates_dir = templates_dir
  @mustache = Mustache.new
  @mustache.raise_on_context_miss = true
  @mustache.template_path = templates_dir
end

Public Instance Methods

generate_src() click to toggle source

@return [Enumerable<String,String>] Returns an enumerable of

file paths and file contents as strings.
# File lib/gem-bootstrap/source_generator.rb, line 25
def generate_src
  Enumerator.new do |y|
    Dir.glob("#{templates_dir}/**/{.*,*}.mustache").each do |template_path|
      y << [
        src_path(template_path),
        src_code(template_path),
      ]
    end
  end
end

Private Instance Methods

render(template) click to toggle source
# File lib/gem-bootstrap/source_generator.rb, line 52
def render(template)
  @mustache.render(template, @config)
end
src_code(template_path) click to toggle source
# File lib/gem-bootstrap/source_generator.rb, line 48
def src_code(template_path)
  render(File.read(template_path))
end
src_path(path) click to toggle source

The path contains two things that must be removed or replaced:

* Prune ".mustache" from the end of the string
* Expand mustache variables, e.g. '{{gem_name}}'
# File lib/gem-bootstrap/source_generator.rb, line 43
def src_path(path)
  path = path[(templates_dir.length + 1)..-10]
  render(path)
end