-
Notifications
You must be signed in to change notification settings - Fork 12
/
install.rb
83 lines (73 loc) · 3 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#This Install script is for Rails Plugin Installation. If using the RubyAMF Lite this is not needed.
begin
require 'fileutils'
overwrite = true
if !File.exist?('./config/rubyamf_config.rb')
FileUtils.copy_file("./vendor/plugins/rubyamf_plugin/rails_installer_files/rubyamf_config.rb", "./config/rubyamf_config.rb", false)
end
FileUtils.copy_file("./vendor/plugins/rubyamf_plugin/rails_installer_files/rubyamf_controller.rb","./app/controllers/rubyamf_controller.rb",false)
FileUtils.copy_file("./vendor/plugins/rubyamf_plugin/rails_installer_files/rubyamf_helper.rb","./app/helpers/rubyamf_helper.rb",false)
FileUtils.copy_file("./vendor/plugins/rubyamf_plugin/rails_installer_files/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
#fosrias
#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
#fosrias: Add version correct route
File.open('./config/routes.rb', 'r') do |f|
while line = f.gets
if line.match("map.rubyamf_gateway 'rubyamf_gateway', :controller => 'rubyamf', :action => 'gateway") &&
Rails::VERSION::MAJOR < 3 || line.match("match 'rubyamf/gateway', :to => 'rubyamf#gateway'") #Rails 3 route
route_amf_controller = false
break
end
end
end
if route_amf_controller
routes = File.read('./config/routes.rb')
routes_regexp = Rails::VERSION::MAJOR < 3 ? /(ActionController::Routing::Routes.draw do \|map\|)/ : /(Application.routes.draw do)/
updated_routes = routes.gsub(routes_regexp) do |s|
if Rails::VERSION::MAJOR < 3
"#{$1}\n map.rubyamf_gateway 'rubyamf_gateway', :controller => 'rubyamf', :action => 'gateway'\n"
else
"#{$1}\n match 'rubyamf/gateway', :to => 'rubyamf#gateway'\n" #Rails 3 route
end
end
File.open('./config/routes.rb', 'w') do |file|
file.write updated_routes
end
end
#fosrias
rescue Exception => e
puts "ERROR INSTALLING RUBYAMF: " + e.message
end