Sha256: e14e510a559bd9a55119ba02233ecbffdcecb34574b6557684c551eb467af465

Contents?: true

Size: 839 Bytes

Versions: 6

Compression:

Stored size: 839 Bytes

Contents

# frozen_string_literal: true

module Neptuno
  module TTY
    # Wrapper class for TTY gem
    module File
      TTY = ::TTY::File
      ABORT_MESSAGE = 'fatal: not a Neptuno repository (or any of the parent directories)'

      def file
        TTY
      end

      # define path helpers
      def project
        neptuno_path.split('/').last
      end

      def in_service?
        Dir.pwd.include?("#{neptuno_path}/services/")
      end

      def service
        ENV['PWD'].match(%r{services/([^/]*)})&.captures&.first
      end

      def neptuno_path
        return @base_path if @base_path

        pwd = Dir.pwd
        loop do
          return pwd if pwd == ''
          return @base_path = pwd if Dir.children(pwd).include?('neptuno.yml')

          pwd = pwd.split('/')[0..-2].join('/')
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
neptuno-1.0.6 lib/neptuno/tty/file.rb
neptuno-1.0.5 lib/neptuno/tty/file.rb
neptuno-1.0.3 lib/neptuno/tty/file.rb
neptuno-1.0.2 lib/neptuno/tty/file.rb
neptuno-1.0.1 lib/neptuno/tty/file.rb
neptuno-1.0.0 lib/neptuno/tty/file.rb