Sha256: 8b8bf57424b4a69900818896dbcff919b35feb03a4479b879df73632058c58f5

Contents?: true

Size: 749 Bytes

Versions: 26

Compression:

Stored size: 749 Bytes

Contents

module App
  # -- app root ---------------------------------------------------------------
  
  module Root
    def self.find_starting_in(dir)
      if is_root?(dir)
        dir 
      elsif !dir.sub!(/\/[^\/]+$/, "")
        nil
      else
        find_starting_in(dir)
      end
    end

    def self.is_root?(dir)
      File.exists?("#{dir}/config.ru") || 
      File.exists?("#{dir}/Gemfile") ||
      File.exists?("#{dir}/Procfile")
    end
    
    def self.find
      find_starting_in(Dir.getwd) || raise("Could not find application root for #{dir}")
    end

    def root=(root)
      @root = root
    end

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

  extend Root
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
radiospiel-app-0.2.3 lib/app/app/root.rb
radiospiel-app-0.2.2 lib/app/app/root.rb
radiospiel-app-0.2.1 lib/app/app/root.rb
radiospiel-app-0.2.0 lib/app/app/root.rb
radiospiel-app-0.1.1 lib/app/app/root.rb
radiospiel-app-0.1.0 lib/app/app/root.rb