Class: LucaCmd

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

Class Method Summary collapse

Class Method Details

.check_dir(essential_dir, ext_conf: nil) ⇒ Object

Search app specific dir from pwd either in direct or monorepo configuration. ‘config/’ subdir has priority for consolidating shared config between apps.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/luca_cmd.rb', line 9

def self.check_dir(essential_dir, ext_conf: nil)
  if Dir.exist?('config')
    LucaRecord::CONST.set_configdir(Pathname(Dir.pwd) / 'config')
  end
  unless Dir.exist?('data')
    Dir.glob('*').reject { |f| File.symlink?(f) }
      .find { |f| File.directory?("#{f}/data/#{essential_dir}") }.tap do |d|
      abort "No valid data directory, exit..." if d.nil?

      Dir.chdir(d)
      if Dir.exist?('config')
        LucaRecord::CONST.set_configdir(Pathname(Dir.pwd) / 'config')
      end
    end
  end
  LucaRecord::Base.load_project(Dir.pwd, ext_conf: ext_conf)
  yield
end