Class: Hanami::Utils::LoadPaths

Inherits:
Object
  • Object
show all
Defined in:
gems/gems/hanami-utils-2.2.0.beta1/lib/hanami/utils/load_paths.rb

Overview

A collection of loading paths.

Since:

  • 0.2.0

Instance Method Summary collapse

Constructor Details

#initialize(*paths) ⇒ Hanami::Utils::LoadPaths

Initialize a new collection for the given paths

Parameters:

  • paths (String, Pathname, Array<String>, Array<Pathname>)

    A single or a collection of objects that can be converted into a Pathname

See Also:

Since:

  • 0.2.0

def initialize(*paths)
  @paths = Utils::Kernel.Array(paths)
end

Instance Method Details

#each {|pathname| ... } ⇒ void

This method returns an undefined value.

Iterates through the collection and yields the given block. It skips duplications and raises an error in case one of the paths doesn’t exist.

Yields:

  • (pathname)

    the block of code that acts on the collection

Yield Parameters:

  • pathname (Pathname)

Raises:

  • (Errno::ENOENT)

    if one of the paths doesn’t exist

Since:

  • 0.2.0

def each
  @paths.each do |path|
    yield realpath(path)
  end
end

#freezeObject

It freezes the object by preventing further modifications.

Examples:

require 'hanami/utils/load_paths'

paths = Hanami::Utils::LoadPaths.new
paths.freeze

paths.frozen?  # => true

paths.push '.' # => RuntimeError

See Also:

Since:

  • 0.2.0

def freeze
  super
  @paths.freeze
end

#push(*paths) ⇒ Hanami::Utils::LoadPaths Also known as: <<

Adds the given path(s).

It returns self, so that multiple operations can be performed.

Examples:

Basic usage

require 'hanami/utils/load_paths'

paths = Hanami::Utils::LoadPaths.new
paths.push '.'
paths.push '..', '../..'

Chainable calls

require 'hanami/utils/load_paths'

paths = Hanami::Utils::LoadPaths.new
paths.push('.')
     .push('..', '../..')

Shovel alias (#<<)

require 'hanami/utils/load_paths'

paths = Hanami::Utils::LoadPaths.new
paths << '.'
paths << ['..', '../..']

Chainable calls with shovel alias (#<<)

require 'hanami/utils/load_paths'

paths = Hanami::Utils::LoadPaths.new
paths << '.' << '../..'

Parameters:

  • paths (String, Pathname, Array<String>, Array<Pathname>)

    A single or a collection of objects that can be converted into a Pathname

Returns:

Raises:

  • (RuntimeError)

    if the object was previously frozen

See Also:

Since:

  • 0.2.0

def push(*paths)
  @paths.push(*paths)
  @paths = Kernel.Array(@paths)
  self
end