Module: Utilities

Defined in:
lib/rhoconnect/utilities.rb

Instance Method Summary collapse

Instance Method Details

#archive(path) ⇒ Object



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

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

#ask(msg) ⇒ Object



42
43
44
45
# File 'lib/rhoconnect/utilities.rb', line 42

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

#cmd(cmd) ⇒ Object

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



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

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

#jruby?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/rhoconnect/utilities.rb', line 78

def jruby?
  defined?(JRUBY_VERSION)
end

#load_settings(file) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/rhoconnect/utilities.rb', line 47

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



14
15
16
17
18
19
20
21
# File 'lib/rhoconnect/utilities.rb', line 14

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)


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

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

#post(path, params) ⇒ Object



23
24
25
26
27
# File 'lib/rhoconnect/utilities.rb', line 23

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


29
30
31
32
33
34
35
36
# File 'lib/rhoconnect/utilities.rb', line 29

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

cmd



10
11
12
# File 'lib/rhoconnect/utilities.rb', line 10

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

#report_missing_serverObject



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

def report_missing_server
  msg ="Could not find 'thin' or 'mongrel' on your system.  Please install one:\ngem install thin\nor\ngem install mongrel\n"
  puts msg
  exit 1
end

#rhoconnect_pidObject



61
62
63
64
65
66
67
68
# File 'lib/rhoconnect/utilities.rb', line 61

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



57
58
59
# File 'lib/rhoconnect/utilities.rb', line 57

def rhoconnect_socket
  '/tmp/rhoconnect.dtach'
end

#ruby19?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/rhoconnect/utilities.rb', line 74

def ruby19?
  RUBY_VERSION =~ /1.9/ 
end

#thin?Boolean

Returns:

  • (Boolean)


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

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

#trinidad?Boolean

def jetty_rackup?

  'jruby -S jetty-rackup'
end

Returns:

  • (Boolean)


115
116
117
# File 'lib/rhoconnect/utilities.rb', line 115

def trinidad?
  'bundle exec jruby -S trinidad -p 9292 -r config.ru'
end

#windows?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/rhoconnect/utilities.rb', line 70

def windows?
  RUBY_PLATFORM =~ /(win|w)32$/
end