module PuppetRepl::Support::Functions

Public Instance Methods

function_files() click to toggle source

returns a array of function files which is only required when displaying the function map, puppet will load each function on demand in the future we may want to utilize the puppet loaders to find these things

# File lib/puppet-repl/support/functions.rb, line 7
def function_files
  search_dirs = lib_dirs.map do |lib_dir|
    [File.join(lib_dir, 'puppet', 'functions', '**', '*.rb'),
      File.join(lib_dir, 'functions', '**', '*.rb'),
     File.join(lib_dir, 'puppet', 'parser', 'functions', '*.rb')
     ]
  end
  # add puppet lib directories
  search_dirs << [File.join(puppet_lib_dir, 'puppet', 'functions', '**', '*.rb'),
    File.join(puppet_lib_dir, 'puppet', 'parser', 'functions', '*.rb')
   ]
  Dir.glob(search_dirs.flatten)
end
function_map() click to toggle source

returns a map of functions

# File lib/puppet-repl/support/functions.rb, line 27
def function_map
  unless @functions
    do_initialize
    @functions = {}
    function_files.each do |file|
      obj = {}
      name = File.basename(file, '.rb')
      obj[:name] = name
      obj[:parent] = mod_finder.match(file)[1]
      @functions["#{obj[:parent]}::#{name}"] = obj
    end
  end
  @functions
end
lib_dirs() click to toggle source

gather all the lib dirs

# File lib/puppet-repl/support/functions.rb, line 51
def lib_dirs
  dirs = modules_paths.map do |mod_dir|
    Dir["#{mod_dir}/*/lib"].entries
  end.flatten
  dirs + [puppet_repl_lib_dir]
end
load_lib_dirs() click to toggle source

load all the lib dirs so puppet can find the functions at this time, this function is not being used

# File lib/puppet-repl/support/functions.rb, line 60
def load_lib_dirs
  lib_dirs.each do |lib|
    $LOAD_PATH << lib
  end
end
mod_finder() click to toggle source

returns either the module name or puppet version

# File lib/puppet-repl/support/functions.rb, line 22
def mod_finder
  @mod_finder ||= Regexp.new('\/([\w\-\.]+)\/lib')
end
resolve_paths(loaders) click to toggle source

returns an array of module loaders that we may need to use in the future in order to parse all types of code (ie. functions) For now this is not being used.

# File lib/puppet-repl/support/functions.rb, line 45
def resolve_paths(loaders)
  mod_resolver = loaders.instance_variable_get(:@module_resolver)
  all_mods = mod_resolver.instance_variable_get(:@all_module_loaders)
end