Module: App::Root

Included in:
App
Defined in:
lib/app/app/root.rb

Overview

– app root —————————————————————

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.findObject



22
23
24
# File 'lib/app/app/root.rb', line 22

def self.find
  find_starting_in(Dir.getwd) || raise("Could not find application root for #{dir}")
end

.find_starting_in(dir) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/app/app/root.rb', line 6

def self.find_starting_in(dir)
  if is_root?(dir)
    dir 
  elsif !dir.sub!(/\/[^\/]+$/, "")
    nil
  else
    find_starting_in(dir)
  end
end

.is_root?(dir) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
# File 'lib/app/app/root.rb', line 16

def self.is_root?(dir)
  File.exists?("#{dir}/config.ru") || 
  File.exists?("#{dir}/Gemfile") ||
  File.exists?("#{dir}/Procfile")
end

Instance Method Details

#rootObject



30
31
32
# File 'lib/app/app/root.rb', line 30

def root
  @root ||= Root.find.tap { |root| App.logger.warn "Application root is #{root}" }
end

#root=(root) ⇒ Object



26
27
28
# File 'lib/app/app/root.rb', line 26

def root=(root)
  @root = root
end