class Riml::RimlFileCommandNode

riml_include, riml_source

Public Class Methods

new(*) click to toggle source
Calls superclass method Riml::CallNode::new
# File lib/riml/nodes.rb, line 334
def initialize(*)
  super
  if arguments.empty? || !arguments.all? { |arg| arg.is_a?(StringNode) }
    error = Riml::UserArgumentError.new(
      "#{name.inspect} error: must pass string(s) (name of file(s))",
      self
    )
    raise error
  end
end

Public Instance Methods

each_existing_file!() { |basename, full_path| ... } click to toggle source

yields basename and full file path for each existing file found in Riml.source_path or Riml.include_path

# File lib/riml/nodes.rb, line 347
def each_existing_file!
  files = {}
  # FIXME: This is a bit of a hack, making sure the include path or source
  # path is properly cached in case `Riml.{include|source}_path` hasn't been
  # called already
  path_dirs
  file_variants.each do |(fname_given, fname_ext_added)|
    if (full_path = Riml.path_cache.file(path_dirs, fname_given))
      files[fname_given] = full_path
    elsif (full_path = Riml.path_cache.file(path_dirs, fname_ext_added))
      add_ext_to_filename(fname_given)
      files[fname_ext_added] = full_path
    else
      error_msg = "#{fname_given.inspect} could not be found in " \
        "Riml.#{name.sub('riml_', '')}_path (#{path_dirs.join(':').inspect})"
      error = Riml::FileNotFound.new(error_msg, self)
      raise error
    end
  end
  return files unless block_given?
  # all files exist
  files.each do |basename, full_path|
    begin
      yield basename, full_path
    rescue Riml::IncludeFileLoop, Riml::SourceFileLoop
      arguments.delete_if { |arg| arg.value == basename }
    end
  end
end

Private Instance Methods

add_ext_to_filename(fname) click to toggle source
# File lib/riml/nodes.rb, line 395
def add_ext_to_filename(fname)
  arg = arguments.detect { |a| a.value == fname }
  return unless arg
  arg.value = file_variants_for_arg(arg).last
end
file_variants() click to toggle source
# File lib/riml/nodes.rb, line 387
def file_variants
  arguments.map { |arg| file_variants_for_arg(arg) }
end
file_variants_for_arg(arg) click to toggle source
# File lib/riml/nodes.rb, line 391
def file_variants_for_arg(arg)
  [arg.value, "#{arg.value}.riml"]
end
path_dirs() click to toggle source
# File lib/riml/nodes.rb, line 379
def path_dirs
  if name == 'riml_include'
    Riml.include_path
  else
    Riml.source_path
  end
end