-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.rb
24 lines (19 loc) · 895 Bytes
/
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
require 'pathname'
def path(s); Pathname.new(s).cleanpath.to_s end
this_path = path File.dirname(__FILE__)
require path(this_path + '/../../../config/boot')
require 'fileutils'
config_path = path("#{RAILS_ROOT}/config")
environment_path = path("#{config_path}/environment.rb")
initializers_path = path("#{config_path}/initializers")
initializer_template_path = path(this_path + "/install/initializer.rb")
initializer_destination = path("#{initializers_path}/railz_scout.rb")
unless File.exists? initializers_path
FileUtils.mkdir_p initializers_path
required = initializer_destination.sub(/\.rb$/, '')
open(environment_path, 'a') do |f|
f.write "\n\n# == Added by RailzScout:\n"
f.write "require '#{required}'\n"
end if IO.read(environment_path).grep(/#{required}/).empty?
end
FileUtils.cp initializer_template_path, initializer_destination