Module: Utilities

Defined in:
lib/rhoconnect/utilities.rb

Instance Method Summary collapse

Instance Method Details

#archive(path) ⇒ Object



35
36
37
# File 'lib/rhoconnect/utilities.rb', line 35

def archive(path)
  File.join(path,File.basename(path))+'.zip'
end

#ask(msg) ⇒ Object



39
40
41
42
# File 'lib/rhoconnect/utilities.rb', line 39

def ask(msg)
  print msg
  STDIN.gets.chomp
end

#cmd(cmd) ⇒ Object

Prints the command to be issued and then issues it to system



6
7
8
9
# File 'lib/rhoconnect/utilities.rb', line 6

def cmd(cmd)
  puts cmd
  system "#{cmd}"
end

#dtach_installed?Boolean

Returns:

  • (Boolean)


117
118
119
120
# File 'lib/rhoconnect/utilities.rb', line 117

def dtach_installed?
  return false if windows? # n/a on windows
  `which dtach` != ''
end

#jruby?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/rhoconnect/utilities.rb', line 80

def jruby?
  defined?(JRUBY_VERSION)
end

#load_settings(file) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/rhoconnect/utilities.rb', line 44

def load_settings(file)
  begin
    $settings = YAML.load_file(file)
  rescue Exception => e
    puts "Error opening settings file #{file}: #{e}."
    puts e.backtrace.join("\n")
    raise e
  end
end

#mk_bin_dir(bin_dir) ⇒ Object

cmd



11
12
13
14
15
16
17
18
# File 'lib/rhoconnect/utilities.rb', line 11

def mk_bin_dir(bin_dir)
  begin
    mkdir_p bin_dir unless File.exists?(bin_dir)
  rescue
    puts "Can't create #{bin_dir}, maybe you need to run command as root?"
    exit 1
  end
end

#mongrel?Boolean

Returns:

  • (Boolean)


93
94
95
96
97
98
99
100
# File 'lib/rhoconnect/utilities.rb', line 93

def mongrel?
  begin
    require 'mongrel'
    'bundle exec rackup -s mongrel'
  rescue LoadError
    nil
  end
end

#post(path, params) ⇒ Object



20
21
22
23
24
# File 'lib/rhoconnect/utilities.rb', line 20

def post(path,params)
  req = Net::HTTP.new($host,$port)
  resp = req.post(path, params.to_json, 'Content-Type' => 'application/json')
  print_resp(resp, resp.is_a?(Net::HTTPSuccess) ? true : false)
end


26
27
28
29
30
31
32
33
# File 'lib/rhoconnect/utilities.rb', line 26

def print_resp(resp,success=true)
  if success
    puts "=> OK"
  else
    puts "=> FAILED"
  end
  puts "=> " + resp.body if resp and resp.body and resp.body.length > 0
end

#redis_homeObject



72
73
74
# File 'lib/rhoconnect/utilities.rb', line 72

def redis_home
  ENV['REDIS_HOME'] || File.join($redis_dest,$redis_ver)
end

#report_missing_serverObject



102
103
104
105
106
107
108
109
110
111
# File 'lib/rhoconnect/utilities.rb', line 102

def report_missing_server
  msg =<<-EOF
Could not find 'thin' or 'mongrel' on your system.  Please install one:
gem install thin
or
gem install mongrel
EOF
  puts msg
  exit 1
end

#rhoconnect_pidObject



58
59
60
61
62
63
64
65
# File 'lib/rhoconnect/utilities.rb', line 58

def rhoconnect_pid
  if windows?
	  Dir.mkdir 'C:/TMP' unless File.directory? 'C:/TMP'
	  'C:/TMP/rhoconnect.pid'
  else
    '/tmp/rhoconnect.pid'
  end
end

#rhoconnect_socketObject



54
55
56
# File 'lib/rhoconnect/utilities.rb', line 54

def rhoconnect_socket
  '/tmp/rhoconnect.dtach'
end

#supported_mri_ruby?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/rhoconnect/utilities.rb', line 76

def supported_mri_ruby?
  RUBY_VERSION =~ /^1\.9\.\d/ || RUBY_VERSION =~ /^2\.\d+\.\d+/
end

#thin?Boolean

Returns:

  • (Boolean)


84
85
86
87
88
89
90
91
# File 'lib/rhoconnect/utilities.rb', line 84

def thin?
  begin
    require 'thin'
    'bundle exec rackup -s thin'
  rescue LoadError
    nil
  end
end

#trinidad?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/rhoconnect/utilities.rb', line 113

def trinidad?
  'bundle exec jruby -S trinidad'
end

#windows?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/rhoconnect/utilities.rb', line 68

def windows?
  RbConfig::CONFIG['host_os']  =~ /(win|w)32$/
end