Class: Riml::RimlCommandNode

Inherits:
CallNode
  • Object
show all
Defined in:
lib/nodes.rb

Constant Summary

Constants inherited from CallNode

CallNode::ALL_BUILTIN_COMMANDS, CallNode::ALL_BUILTIN_FUNCTIONS

Constants included from Visitable

Visitable::DESCENDANT_OF_REGEX

Constants included from Constants

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

Instance Attribute Summary

Attributes inherited from CallNode

#arguments, #name, #scope_modifier

Attributes included from Visitable

#compiled_output, #force_newline, #parent_node, #scope

Instance Method Summary collapse

Methods inherited from CallNode

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

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

Methods included from FullyNameable

#full_name, included

Methods included from Visitable

#accept, #method_missing, #respond_to?

Constructor Details

#initializeRimlCommandNode

Returns a new instance of RimlCommandNode.



389
390
391
392
393
394
# File 'lib/nodes.rb', line 389

def initialize(*)
  super
  if arguments.empty? || !arguments.all? { |arg| arg.is_a?(StringNode) }
    raise Riml::UserArgumentError, "#{name.inspect} error: must pass string(s) (name of file(s))"
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Riml::Visitable

Instance Method Details

#each_existing_file!Object

yields full file path for each existing file found in Riml.source_path



397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'lib/nodes.rb', line 397

def each_existing_file!
  files = {}
  arguments.map(&:value).each do |file|
    if base_path = paths.detect do |path|
         full = File.join(path, file)
         File.exists?(full)
       end
      files[file] = File.join(base_path, file)
    else
      raise Riml::FileNotFound, "#{file.inspect} could not be found in " \
        "Riml.#{name.sub('riml_', '')}_path (#{paths.join(':').inspect})"
    end
  end
  return files.values 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

#pathsObject



421
422
423
424
425
426
427
# File 'lib/nodes.rb', line 421

def paths
  if name == 'riml_include'
    Riml.include_path
  else
    Riml.source_path
  end
end