config.rb in ruby-station-0.0.4 vs config.rb in ruby-station-0.1.0
- old
+ new
@@ -1,5 +1,6 @@
+require __DIR__("./util/gem_manager")
require 'yaml'
require 'fileutils'
#Encoding.default_external = 'UTF-8'
@@ -7,11 +8,11 @@
VERSION = File.read(__DIR__("VERSION")).chomp
RUNTIME_VERSION = File.read(__DIR__("runtime", "VERSION")).chomp
end
class Conf
- %w(ruby_command gem_command gem_dir gem_bin_dir gem_install_option data_dir server_port).each do |m|
+ %w(ruby_command gem_command gem_dir gem_bin_dir gem_install_option data_dir server_port debug).each do |m|
class_eval <<-EOD
def self.#{m}; @yaml[:#{m}]; end
EOD
end
@@ -32,10 +33,15 @@
}
}
@opt.parse!(ARGV)
end
+ # for unit tests
+ def self.set_home(path)
+ @home = path
+ end
+
def self.load_yaml
yaml_path = File.join(@home, "config.yaml")
unless File.exist?(yaml_path)
Ramaze::Log.warn "#{yaml_path} not found: creating"
FileUtils.makedirs(@home)
@@ -45,26 +51,38 @@
end
YAML.load_file(yaml_path)
end
# TODO: refactor X-(
- def self.init
+ def self.init(home=nil)
+ @home = home if home
@yaml = self.load_yaml
@yaml[:gem_dir] = File.expand_path(@yaml[:gem_dir], @home)
@yaml[:gem_bin_dir] = File.expand_path(@yaml[:gem_bin_dir], @home)
@yaml[:data_dir] = File.expand_path(@yaml[:data_dir], @home)
FileUtils.makedirs(@yaml[:gem_dir])
FileUtils.makedirs(@yaml[:gem_bin_dir])
FileUtils.makedirs(@yaml[:data_dir])
- runtime_ver = RubyStation::RUNTIME_VERSION
- unless GemManager.installed?("ruby-station-runtime", runtime_ver)
- gem_path = __DIR__("runtime/ruby-station-runtime-#{runtime_ver}.gem")
- GemManager.install_file(gem_path)
- end
+ Runtime.install unless Runtime.installed?
+
# unless `#{self.gem_command} sources`.include?("github")
# cmd = "#{self.gem_command} sources -a http://gems.github.com"
# Ramaze::Log.info cmd
# `#{cmd}`
# end
+ end
+
+ module Runtime
+ VERSION = RubyStation::RUNTIME_VERSION
+
+ def self.installed?
+ GemManager.installed?("ruby-station-runtime", VERSION)
+ end
+
+ def self.install
+ path = __DIR__("runtime/ruby-station-runtime-#{VERSION}.gem")
+ GemManager.install_file(path)
+ end
+
end
end