Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 18096053f9
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 66 lines (55 sloc) 2.399 kb
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
# Taken from Railties
def gsub_file(relative_destination, regexp, *args, &block)
  path = relative_destination
  content = File.read(path).gsub(regexp, *args, &block)
  File.open(path, 'wb') { |file| file.write(content) }
end

SWX_RUBY_ROOT = File.dirname(__FILE__)
@getting_started = IO.read(File.join(SWX_RUBY_ROOT, 'README'))

begin
  require 'fileutils'
include FileUtils
  
# Copy config file
  unless File.exist?('./config/swx.yml')
puts '*** Copying config file to config/swx.yml ***'
    cp(File.join(SWX_RUBY_ROOT, 'lib', 'config', 'swx.yml'), './config/swx.yml')
  end
  
# Copy SWX controller
unless File.exist?('./app/controllers/swx_controller.rb')
puts '*** Copying SWX controller to app/controllers/swx_controller.rb ***'
cp(File.join(SWX_RUBY_ROOT, 'lib', 'controllers', 'swx_controller.rb'), './app/controllers/swx_controller.rb')
end

# Create services directory
unless File.exist?('./app/services')
puts '*** Creating services directory at app/services ***'
mkdir('./app/services')
end

# Copy TestDataTypes class to app/services
unless File.exist?('./app/services/test_data_types.rb')
puts '*** Copying TestDataTypes service class to app/services ***'
cp(File.join(SWX_RUBY_ROOT, 'lib', 'services', 'test_data_types.rb'), './app/services/test_data_types.rb')
end

# Copy HelloWorld class to app/services
unless File.exist?('./app/services/hello_world.rb')
puts '*** Copying HelloWorld service class to app/services ***'
cp(File.join(SWX_RUBY_ROOT, 'lib', 'services', 'hello_world.rb'), './app/services/hello_world.rb')
end

# Add route for SWX gateway to routes.rb
puts '*** Adding route for SWX gateway to routes.rb ***'
sentinel = 'ActionController::Routing::Routes.draw do |map|'
gsub_file './config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
"#{match}\n map.swx '/swx', :controller => 'swx', :action => 'gateway'\n"
end

# Check for installation of JSON gem
print '*** Checking if JSON gem is installed'
require 'rubygems'
require 'json'
puts ': JSON gem detected ***'

puts @getting_started
rescue LoadError
puts @getting_started

puts '!!!!! You do not have the JSON gem installed. SWX on Rails will not function without it.'
puts '!!!!! Please "gem install json" to get the JSON gem, then SWX on Rails should be ready to roll.'
rescue Exception => e
  puts 'ERROR INSTALLING SWX Ruby: ' + e.message
end
Something went wrong with that request. Please try again.