class LoomExt::CoreMods::Files

Public Instance Methods

init_action(paths) click to toggle source

TODO: document loom file statements like:

`loom.files("some", "different/paths").cat`
# File lib/loomext/coremods/files.rb, line 9
def init_action(paths)
  @paths = [paths].flatten.compact
end

Private Instance Methods

each_path(action: nil, flags: nil) { |p| ... } click to toggle source

Executes #{action} for each path in #{paths} or #{@paths}. If action is not given, a block is expected to which each path will be passed.

# File lib/loomext/coremods/files.rb, line 18
def each_path(action: nil, flags: nil, &block)
  raise 'use either action or block in each_path' if action && block_given?
  raise 'use either action or block in each_path' unless action || block_given?

  @paths.each do |p|
    next unless p

    raise "prefix relative paths with '.': #{p}" unless p.match /^[.]?\//
    if block
      yield p
    else
      shell.execute action, flags, p
    end
  end

  # Return self for chaining in pattern files
  self
end