Sha256: 188db3e893be2af804bd5c490b879da979737b9b38cf987fbe8ef43f8902a318

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

require 'yaml'
require 'fileutils'

#Encoding.default_external = 'UTF-8'

module RubyStation
  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|
    class_eval <<-EOD
      def self.#{m}; @yaml[:#{m}]; end
    EOD
  end

  def self.db_path
    File.join(@home, "ruby-station.db")
  end

  def self.parse_opt
    @home = File.expand_path("~/.ruby-station")

    @opt = OptionParser.new{|o|
      o.on("--home PATH", "path to save ruby-station data (default: #@home)"){|path|
        @home = File.expand_path(path)
      }
      o.on("-h", "--help", "show this message"){
        puts @opt.to_s
        exit
      }
    }
    @opt.parse!(ARGV)
  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)
      File.open(yaml_path, "w"){|f|
        f.write File.read(__DIR__("sample.config.yaml"))
      }
    end
    YAML.load_file(yaml_path)
  end

  # TODO: refactor X-(
  def self.init
    @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
#    unless `#{self.gem_command} sources`.include?("github")
#      cmd = "#{self.gem_command} sources -a http://gems.github.com"
#      Ramaze::Log.info cmd
#      `#{cmd}`
#    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-station-0.0.4 config.rb