Module: Rhosync::TaskHelper

Defined in:
lib/rhosync/tasks.rb

Instance Method Summary collapse

Instance Method Details

#archive(path) ⇒ Object



23
24
25
# File 'lib/rhosync/tasks.rb', line 23

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

#ask(msg) ⇒ Object



27
28
29
30
# File 'lib/rhosync/tasks.rb', line 27

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

#load_settings(file) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/rhosync/tasks.rb', line 32

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

#mongrel?Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
# File 'lib/rhosync/tasks.rb', line 63

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

#post(path, params) ⇒ Object



8
9
10
11
12
# File 'lib/rhosync/tasks.rb', line 8

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


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

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

#report_missing_serverObject



72
73
74
75
76
77
78
79
80
81
# File 'lib/rhosync/tasks.rb', line 72

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

#rhosync_pidObject



46
47
48
# File 'lib/rhosync/tasks.rb', line 46

def rhosync_pid
  "/tmp/rhosync.pid"
end

#rhosync_socketObject



42
43
44
# File 'lib/rhosync/tasks.rb', line 42

def rhosync_socket
  "/tmp/rhosync.dtach"
end

#thin?Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
# File 'lib/rhosync/tasks.rb', line 54

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

#windows?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/rhosync/tasks.rb', line 50

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