Class: Aggkit::Env::Pathfinder

Inherits:
Object
  • Object
show all
Defined in:
lib/aggkit/env.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Pathfinder

Returns a new instance of Pathfinder.



158
159
160
# File 'lib/aggkit/env.rb', line 158

def initialize path
  @path = File.realpath(File.expand_path(path))
end

Instance Attribute Details

#path ⇒ Object

Returns the value of attribute path.



156
157
158
# File 'lib/aggkit/env.rb', line 156

def path
  @path
end

Instance Method Details

#each_env ⇒ Object



172
173
174
175
176
177
178
179
180
# File 'lib/aggkit/env.rb', line 172

def each_env
  Dir.chdir(File.join(path, 'envs')) do 
    Dir.glob('**/*').select do |f|
      File.directory? f
    end.select do |f|
      File.exists?(File.join(f, '.env')) || File.exists?(File.join(f, 'docker-compose.yml')) || File.exists?(File.join(f, 'docker-compose.yaml')) 
    end.sort
  end
end

#each_parent ⇒ Object



162
163
164
165
166
167
168
169
170
# File 'lib/aggkit/env.rb', line 162

def each_parent
  current = path.split(File::SEPARATOR)
  Enumerator.new do |y|
    while !current.empty? do
      y << current.join(File::SEPARATOR)
      current.pop
    end
  end
end