Sha256: 105649779ed575da4aead76272df7eec22a789c1c1f5fca7dc4194a500c1050e

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require_relative 'aid/version'

module Aid
  def self.load_paths
    @load_paths ||= [
      File.expand_path(File.dirname(__FILE__) + '/aid/scripts'),
      '.aid',
      "#{Aid.project_root}/.aid",
      ENV['AID_PATH']
    ].compact
  end

  def self.load_scripts!
    load_paths.each do |path|
      Dir.glob("#{path}/*.rb").each do |file|
        require File.expand_path(file) unless %r{/config\.rb$}.match?(file)
      end
    end
  end

  def self.load_configs!
    load_paths.each do |path|
      config = File.expand_path("#{path}/config.rb")
      require config if File.exist?(config)
    end
  end

  def self.script_name
    ARGV.first
  end

  def self.script_args
    ARGV[1..-1]
  end

  def self.project_root
    @project_root ||= begin
      current_search_dir = Dir.pwd

      loop do
        git_dir = "#{current_search_dir}/.git"

        return current_search_dir if Dir.exist?(git_dir)
        break if current_search_dir == '/'

        current_search_dir = File.expand_path("#{current_search_dir}/..")
      end

      nil
    end
  end
end

require_relative 'aid/colorize'
require_relative 'aid/inheritable'
require_relative 'aid/plugins'
require_relative 'aid/script'
require_relative 'aid/scripts'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
abtion-aid-0.3.2 lib/aid.rb
abtion-aid-0.3.1 lib/aid.rb
abtion-aid-0.2.0 lib/aid.rb