Cuprum::Cli

A command-line utility powered by Cuprum that provides tools and utilities for defining command-line tools.

Module: Cuprum::Cli::Files::Templates

Parent Namespace
Cuprum::Cli::Files
Defined In
lib/cuprum/cli/files/templates.rb

Table Of Contents

Overview

Namespace for template files and implementations.

Back To Top

Constants

BasicTemplate

= Cuprum::Cli::Files::Template.define do private

def process(contents: nil, **parameters) step { validate_contents(contents) }

apply_engine(contents, **parameters)   end

def tools SleepingKingStudios::Tools::Toolbelt.instance end

def validate_contents(contents) # rubocop:disable Metrics/MethodLength validator = tools.assertions.aggregator_class.new

validator.validate_presence(contents, as: 'contents')
validator.validate_instance_of(
  contents,
  as:       'contents',
  expected: String
)

return Cuprum::Result.new if validator.empty?

error = Cuprum::Errors::InvalidParameters.new(
  command_class: self.class,
  failures:      validator.each.to_a
)
failure(error)   end end</code></span>

Data class representing a template that returns the input contents.

FileTemplate

= Cuprum::Cli::Files::Template.define(:file_path, :file_system) \ do class_methods = Module.new do # Converts a raw file path to a template object. # # @param file_path [String] the input file path. # # @return [FileTemplate] the generated template. def build(file_path) engine = case File.extname(file_path) when '.erb' then Cuprum::Cli::Files::Engines::ERB end

  new(engine:, file_path:)
end   end   const_set(:ClassMethods, class_methods)

def self.included(other) super

other.extend(const_get(:ClassMethods))   end

# @overload initialize(file_path:, engine: nil) # @param engine [Symbol] the engine used to generate the template # contents. # @param file_path [String] the path to the template file. def initialize(file_path:, engine: nil, file_system: nil, **) file_system ||= Cuprum::Cli::Dependencies.provider.get(‘file_system’)

super(engine:, file_path:, file_system:, **)   end

private

def raw_value success(file_system.read_file(file_path)) rescue Cuprum::Cli::Dependencies::FileSystem::FileNotFoundError error = Cuprum::Cli::Files::Errors::MissingTemplate.new( message: ‘unable to generate file’, template_path: file_path ) failure(error) end

def template_name = file_path end</code></span>

Data class representing a template defined on a file.

StringTemplate

= Cuprum::Cli::Files::Template.define(:raw_template) do class_methods = Module.new do # Converts a raw template string to a template object. # # @param raw_template [String] the unprocessed template string. # # @return [StringTemplate] the generated template. def build(raw_template) = new(engine: nil, raw_template:) end const_set(:ClassMethods, class_methods)

def self.included(other) super

other.extend(const_get(:ClassMethods))   end

private

def raw_value = raw_template end</code></span>

Data class representing a string literal template.

Back To Top

Class Methods

.resolve(maybe_template) => Cuprum::Cli::Files::Template

Converts a raw input string to a template object.

Parameters

Returns

Raises

Back To Top


Back to Documentation | Versions | 0.2 | Reference | Cuprum | Cuprum::Cli | Cuprum::Cli::Files