Class: Hanami::Utils::LoadPaths
- Inherits:
-
Object
- Object
- Hanami::Utils::LoadPaths
- Defined in:
- lib/hanami/utils/load_paths.rb
Overview
A collection of loading paths.
Instance Method Summary collapse
- #==(other) ⇒ Object private
-
#each {|pathname| ... } ⇒ void
Iterates through the collection and yields the given block.
-
#freeze ⇒ Object
It freezes the object by preventing further modifications.
-
#initialize(*paths) ⇒ Hanami::Utils::LoadPaths
constructor
Initialize a new collection for the given paths.
-
#initialize_copy(original) ⇒ Object
private
It specifies the policy for initialize copies of the object, when #clone or #dup are invoked.
-
#push(*paths) ⇒ Hanami::Utils::LoadPaths
(also: #<<)
Adds the given path(s).
Constructor Details
#initialize(*paths) ⇒ Hanami::Utils::LoadPaths
Initialize a new collection for the given paths
22 23 24 |
# File 'lib/hanami/utils/load_paths.rb', line 22 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.
144 145 146 147 148 149 150 151 |
# File 'lib/hanami/utils/load_paths.rb', line 144 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 through the collection and yields the given block. It skips duplications and raises an error in case one of the paths doesn’t exist.
65 66 67 68 69 |
# File 'lib/hanami/utils/load_paths.rb', line 65 def each @paths.each do |path| yield realpath(path) end end |
#freeze ⇒ Object
It freezes the object by preventing further modifications.
137 138 139 140 |
# File 'lib/hanami/utils/load_paths.rb', line 137 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.
49 50 51 |
# File 'lib/hanami/utils/load_paths.rb', line 49 def initialize_copy(original) @paths = original.instance_variable_get(:@paths).dup end |
#push(*paths) ⇒ Hanami::Utils::LoadPaths Also known as: <<
Adds the given path(s).
It returns self, so that multiple operations can be performed.
114 115 116 117 118 |
# File 'lib/hanami/utils/load_paths.rb', line 114 def push(*paths) @paths.push(*paths) @paths = Kernel.Array(@paths) self end |