Class: Lotus::Utils::LoadPaths

Inherits:
Object
  • Object
show all
Defined in:
lib/lotus/utils/load_paths.rb

Overview

A collection of loading paths.

Since:

  • 0.2.0

Instance Method Summary collapse

Constructor Details

#initialize(*paths) ⇒ Lotus::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



20
21
22
# File 'lib/lotus/utils/load_paths.rb', line 20

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

Instance Method Details

#==(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.6.0



142
143
144
145
146
147
148
149
# File 'lib/lotus/utils/load_paths.rb', line 142

def ==(other)
  case other
  when self.class
    other.paths == paths
  else
    other == paths
  end
end

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

This method returns an undefined value.

Iterates thru 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



63
64
65
66
67
# File 'lib/lotus/utils/load_paths.rb', line 63

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

#freezeObject

It freezes the object by preventing further modifications.

Examples:

require 'lotus/utils/load_paths'

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

paths.frozen?  # => true

paths.push '.' # => RuntimeError

See Also:

Since:

  • 0.2.0



135
136
137
138
# File 'lib/lotus/utils/load_paths.rb', line 135

def freeze
  super
  @paths.freeze
end

#initialize_copy(original) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

It specifies the policy for initialize copies of the object, when #clone or #dup are invoked.

Examples:

require 'lotus/utils/load_paths'

paths  = Lotus::Utils::LoadPaths.new '.'
paths2 = paths.dup

paths  << '..'
paths2 << '../..'

paths
  # => #<Lotus::Utils::LoadPaths:0x007f84e0cad430 @paths=[".", ".."]>

paths2
  # => #<Lotus::Utils::LoadPaths:0x007faedc4ad3e0 @paths=[".", "../.."]>

See Also:

Since:

  • 0.2.0



47
48
49
# File 'lib/lotus/utils/load_paths.rb', line 47

def initialize_copy(original)
  @paths = original.instance_variable_get(:@paths).dup
end

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

Adds the given path(s).

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

Examples:

Basic usage

require 'lotus/utils/load_paths'

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

Chainable calls

require 'lotus/utils/load_paths'

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

Shovel alias (#<<)

require 'lotus/utils/load_paths'

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

Chainable calls with shovel alias (#<<)

require 'lotus/utils/load_paths'

paths = Lotus::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



112
113
114
115
116
# File 'lib/lotus/utils/load_paths.rb', line 112

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