Module: Raketeer::Util

Defined in:
lib/raketeer/util.rb

Overview

Author:

  • Jonathan Bradley Whited

Since:

  • 0.2.2

Constant Summary collapse

TRUE_BOOLS =

Since:

  • 0.2.4

%w[ 1 on t true y yes ].freeze

Class Method Summary collapse

Class Method Details

.find_github_usernameObject

This is pretty hacky…

Since:

  • 0.2.8



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/raketeer/util.rb', line 24

def self.find_github_username
  Dir.glob('*.gemspec') do |file|
    File.foreach(file) do |line|
      md = line.match(%r{(github\.com/)([^/]+)}i)

      next if md.nil? || md.length < 3

      return md[2].gsub(/\s+/,'')
    end
  end

  return nil
end

.find_main_executable(bin_dir = 'bin') ⇒ Object

Since:

  • 0.2.2



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/raketeer/util.rb', line 38

def self.find_main_executable(bin_dir='bin')
  # Try the bin/ dir
  main_exe = Dir.glob(File.join(bin_dir,'*'))

  return File.basename(main_exe[0]) if main_exe.length == 1

  # Try using the main module
  main_mod = find_main_module

  if !main_mod.nil?
    main_exe = File.join(bin_dir,main_mod)

    return main_mod if File.exist?(main_exe)
  end

  return nil
end

.find_main_module(lib_dir = 'lib') ⇒ Object

Since:

  • 0.2.2



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/raketeer/util.rb', line 56

def self.find_main_module(lib_dir='lib')
  # Try the lib/ dir
  main_file = Dir.glob(File.join(lib_dir,'*.rb'))

  return File.basename(main_file[0],'.*') if main_file.length == 1

  # Try the Gemspec
  main_file = Dir.glob('*.gemspec')

  return File.basename(main_file[0],'.*') if main_file.length == 1

  return nil
end

.get_env_bool(env_name, def_value = nil) ⇒ Object

Since:

  • 0.2.7



71
72
73
74
75
76
77
78
79
# File 'lib/raketeer/util.rb', line 71

def self.get_env_bool(env_name,def_value=nil)
  value = ENV[env_name]

  if value.nil? || (value = value.to_s.strip).empty?
    return def_value
  end

  return to_bool(value)
end

.to_bool(obj) ⇒ Object

Since:

  • 0.2.4



82
83
84
# File 'lib/raketeer/util.rb', line 82

def self.to_bool(obj)
  return TRUE_BOOLS.include?(obj.to_s.downcase)
end