Module: Rndr

Defined in:
lib/rndr.rb,
lib/rndr/cli.rb,
lib/rndr/util.rb,
lib/rndr/version.rb,
lib/rndr/template.rb

Overview

Rndr base module

Author:

Defined Under Namespace

Classes: CLI, Template

Constant Summary collapse

VERSION =
File.read(
  File.expand_path('../../../version.txt', __FILE__)
).chomp

Class Method Summary collapse

Class Method Details

.matches(path:, ext: 'erb', ignore_path: File.join(Dir.pwd, '.rndrignore')) ⇒ Array<String>

Accepts a path (either file or directory), a file extension, and the name of a file within the working directory that contains a list of file glob patterns to be skipped. It returns an array of filtered matched paths.

Parameters:

  • path (String)

    The path to the template file or directory.

  • ext (String) (defaults to: 'erb')

    The File name extension to identify template files.

  • ignore_path (String) (defaults to: File.join(Dir.pwd, '.rndrignore'))

    The path to ignore file.

Returns:

  • (Array<String>)

    list of paths to matching results.



15
16
17
18
19
20
21
# File 'lib/rndr/util.rb', line 15

def self.matches(path:, ext: 'erb', ignore_path: File.join(Dir.pwd, '.rndrignore'))
  matched_paths = match_files(path: File.absolute_path(path), ext: ext)
  ignore_file_path = File.absolute_path(ignore_path)
  return filter_ignored_paths(path_list: matched_paths, ignore_path: ignore_file_path) if
         !matched_paths.empty? && File.exist?(ignore_file_path)
  matched_paths
end

.read_vars(path:, merge: true, merge_opts: {}) ⇒ Hash

Accepts a file or directory and will attempt to parse the discovered file(s) as either json or yaml. It will then be returned as a hash intended for use with seeding the binding used for template rendering in Rndr::Template#render.

Parameters:

  • path (String)

    The path to the vars file or directory. Will process both json and yaml.

  • merge (Boolean) (defaults to: true)

    True to enable recursive merge of hashes.

  • merge_opts (Hash) (defaults to: {})

    A hash of options to be passed to the deep_merge method

Returns:

  • (Hash)

    A hash containing the processed variables. Will be used to send to the binding of a rendered template. See Rndr::Template#render for more information.



31
32
33
34
35
36
37
# File 'lib/rndr/util.rb', line 31

def self.read_vars(path:, merge: true, merge_opts: {})
  vars_path = File.absolute_path(path)
  return read_vars_file(vars_path) if File.file?(vars_path)
  return read_vars_dir(path: vars_path, merge: merge, merge_opts: merge_opts) if
         File.directory?(vars_path)
  {}
end