-
Notifications
You must be signed in to change notification settings - Fork 5
/
install.rb
57 lines (48 loc) · 1.96 KB
/
install.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#This Install script is for Rails Plugin Installation. If using the RubyAMF Lite this is not needed.
begin
require 'fileutils'
overwrite = true
install_files_root = File.join( File.dirname(__FILE__), "rails_installer_files")
if !File.exist?('./config/rubyamf_config.rb')
FileUtils.copy_file( File.join(install_files_root, "rubyamf_config.rb", "./config/rubyamf_config.rb", false)
end
FileUtils.copy_file( File.join(install_files_root, "rubyamf_controller.rb","./app/controllers/rubyamf_controller.rb",false)
FileUtils.copy_file( File.join(install_files_root, "rubyamf_helper.rb","./app/helpers/rubyamf_helper.rb",false)
FileUtils.copy_file( File.join(install_files_root, "crossdomain.xml","./public/crossdomain.xml", false)
mime = true
mime_types_file_exists = File.exists?('./config/initializers/mime_types.rb')
mime_config_file = mime_types_file_exists ? './config/initializers/mime_types.rb' : './config/environment.rb'
File.open(mime_config_file, "r") do |f|
while line = f.gets
if line.match(/application\/x-amf/)
mime = false
break
end
end
end
if mime
File.open(mime_config_file,"a") do |f|
f.puts "\nMime::Type.register \"application/x-amf\", :amf"
end
end
route_amf_controller = true
File.open('./config/routes.rb', 'r') do |f|
while line = f.gets
if line.match("map.rubyamf_gateway 'rubyamf_gateway', :controller => 'rubyamf', :action => 'gateway")
route_amf_controller = false
break
end
end
end
if route_amf_controller
routes = File.read('./config/routes.rb')
updated_routes = routes.gsub(/(ActionController::Routing::Routes.draw do \|map\|)/) do |s|
"#{$1}\n map.rubyamf_gateway 'rubyamf_gateway', :controller => 'rubyamf', :action => 'gateway'\n"
end
File.open('./config/routes.rb', 'w') do |file|
file.write updated_routes
end
end
rescue Exception => e
puts "ERROR INSTALLING RUBYAMF: " + e.message
end