class Caligari::Application

This class is instantiated and used to run a single invocation of the `caligari` application.

Constants

FLAGS

The flags to be passed to `Pathname#fnmatch?` to filter exclusions.

HOME

The `Pathname` representation of the current user's home directory.

Public Class Methods

new(*paths, **options) click to toggle source

Instantiates a new {Application} instance.

@param paths [Array<String>]

the paths for this {Application} to {#run} on

@param options [Hash]

the hash of options to apply to this {Application}

@return [self]

the initialized {Application} instance
# File lib/caligari/application.rb, line 24
def initialize(*paths, **options)
  @paths = paths.map { |path| Pathname.new(path) }
  options.each do |key, value|
    instance_variable_set(:"@#{key}", value)
  end
  collect_exclusions
end

Public Instance Methods

run() click to toggle source

Runs Caligari.

@return [self]

# File lib/caligari/application.rb, line 35
def run
  @paths.each do |path|
    fail "#{path} is not a valid path" unless path.directory?
    if @traverse
      Dir.chdir(path) do
        each_file(Pathname.new('.')) { |file| link(file) }
      end
    else
      each_file(path) { |file| link(file) }
    end
  end
  self
end

Private Instance Methods

collect_exclusions() click to toggle source

Collects the list of exclusion patterns for Caligari from a combination of XDG configuration directories and the given CLI exclusions.

@note Exclusion patterns are used to filter the files to act upon via the

`Pathname#fnmatch?` instance method. The actual filtering, however,
takes place within {#each_file}.

@return [Array<String>]

the array of patterns to exclude

@see each_file

# File lib/caligari/application.rb, line 60
        def collect_exclusions
  XDG::CONFIG_FILES.each do |file|
    config = YAML::Store.new(file)
    @exclude |= config.transaction { config.fetch(:exclude, []) }
  end
  @exclude
end
each_file(path) { |entry| ... } click to toggle source

Recursively iterates over each file in the given `path`, excluding those which match any of the exclusion patterns collected via the {#collect_exclusions} private instance method. The given `block` is executed for each file.

@param path [Pathname]

the base directory to iterate over

@yieldparam entry [Pathname]

the representation of a file

@return [Array<Pathname>]

@see collect_exclusions

# File lib/caligari/application.rb, line 80
        def each_file(path, &block)
  path.each_child do |entry|
    next if @exclude.any? { |pattern| entry.fnmatch?(pattern, FLAGS) }
    entry.directory? ? each_file(entry, &block) : yield(entry)
  end
end
report(message, stream = $stdout) click to toggle source

Reports the given `message` on the given `stream` if Caligari has been configured to run in verbose or simulation mode.

@param message [#to_s]

the message to report

@param stream [#puts]

the stream to write a message to

@return [nil]

# File lib/caligari/application.rb, line 122
        def report(message, stream = $stdout)
  return unless @verbose || @simulate
  stream.puts message.to_s
end