Class: Riml::RimlFileCommandNode

Inherits:
RimlCommandNode show all
Defined in:
lib/riml/nodes.rb

Overview

riml_include, riml_source

Constant Summary

Constants inherited from CallNode

CallNode::ALL_BUILTIN_COMMANDS, CallNode::ALL_BUILTIN_FUNCTIONS

Constants included from Visitable

Visitable::EMPTY_CHILDREN

Constants included from Constants

Constants::BUILTIN_COMMANDS, Constants::BUILTIN_FUNCTIONS, Constants::COMPARISON_OPERATORS, Constants::COMPILED_STRING_LOCATION, Constants::DEFINE_KEYWORDS, Constants::END_KEYWORDS, Constants::IGNORECASE_CAPABLE_OPERATORS, Constants::KEYWORDS, Constants::REGISTERS, Constants::RIML_CLASS_COMMANDS, Constants::RIML_COMMANDS, Constants::RIML_END_KEYWORDS, Constants::RIML_FILE_COMMANDS, Constants::RIML_KEYWORDS, Constants::SPECIAL_VARIABLE_PREFIXES, Constants::SPLAT_LITERAL, Constants::UNKNOWN_LOCATION_INFO, Constants::VIML_COMMANDS, Constants::VIML_END_KEYWORDS, Constants::VIML_KEYWORDS

Instance Attribute Summary

Attributes inherited from CallNode

#arguments, #name, #scope_modifier, #super_call

Attributes included from Visitable

#compiled_output, #force_newline, #parent_node, #parser_info, #scope

Instance Method Summary collapse

Methods inherited from CallNode

#autoload?, #builtin_command?, #builtin_function?, #children, #force_newline_if_child_call_node?, #method_call?, #must_be_explicit_call?, #remove_parens_wrapper

Methods included from FullyNameable

#full_name, included

Methods included from Visitable

#accept, #children, #force_newline_if_child_call_node?, #location_info

Methods included from Walkable

#child_after, #child_previous_to, #each, #index_by_children, #index_by_member, #insert_after, #insert_before, #next, #previous, #remove, #replace_with

Constructor Details

#initializeRimlFileCommandNode

Returns a new instance of RimlFileCommandNode.



334
335
336
337
338
339
340
341
342
343
# 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

Instance Method Details

#each_existing_file!Object

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



347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# 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