class Swee::Engine
静态化
Public Class Methods
boot!(argv)
click to toggle source
启动服务
# File lib/swee/engine.rb, line 112 def boot! argv cmd = argv.shift || "s" options = parse_options.merge({:cmd => cmd}) case cmd when "new" proj_name = argv.shift if proj_name.nil? puts "格式错误,请输入: swee new 项目名称" return end require_relative './installer' Installer.run(proj_name) return when "g" # => Todo: generation 生成 return else require_files cache_file_mtime @@__instance__ = self.new options parse_cmd cmd,options end end
cache_file_mtime()
click to toggle source
# File lib/swee/engine.rb, line 180 def cache_file_mtime Lodder.cache_file_mtime end
config()
click to toggle source
配置实例
# File lib/swee/engine.rb, line 76 def config instance.send :config end
instance()
click to toggle source
当前实例
# File lib/swee/engine.rb, line 72 def instance @@__instance__ end
new(options)
click to toggle source
# File lib/swee/engine.rb, line 48 def initialize options # 初始化配置 @config = Swee.init_config # 读取用户配置 require_user_appconfig # 合并配置 merge_config! options end
parse_cmd(cmd,options)
click to toggle source
解析命令 c -> 命令行 s -> 启动服务
# File lib/swee/engine.rb, line 139 def parse_cmd cmd,options case cmd when "c" # => 命令行模式 require 'irb' IRB.start when "s" # => 启动服务器 start_server! else raise "命令不合法" end end
parse_options()
click to toggle source
命令行解析
# File lib/swee/engine.rb, line 93 def parse_options options = {} OptionParser.new do |opts| opts.banner = "swee框架使用参数如下" opts.on("-p", "--port PORT", Integer, "端口 (默认: 3000)") do |port| options[:listen] = port end opts.on("-e", "--env ENV", "环境 development 或 production (默认为development)") do |e| options[:env] = e end end.parse! options end
require_files()
click to toggle source
加载全部文件
# File lib/swee/engine.rb, line 152 def require_files # require 加载器 Lodder require_relative './lodder' Lodder.all _app_path = ENV["app_path"] # _app_env = Application.config["app_env"] # if (begin # require "active_record" # rescue # false # end) # ActiveRecord::Base.establish_connection YAML::load(File.open(ENV["app_path"]+'/database.yml'))[_app_env] # end # 加载路由 require File.expand_path('./routes', _app_path) # 加载控制器 Dir.glob("#{_app_path}/controllers/*.rb") { |f| require f } # 加载模型 Dir.glob("#{_app_path}/models/*.rb") { |f| require ENV["app_path"] + "/models/"+File.basename(f, '.*') } end
restart_server!()
click to toggle source
重启服务器
# File lib/swee/engine.rb, line 185 def restart_server! @@__server__ = nil GC.start require_files cache_file_mtime start_server! end
server()
click to toggle source
服务器实例
# File lib/swee/engine.rb, line 80 def server @@__server__ end
start_server!()
click to toggle source
启动服务器
# File lib/swee/engine.rb, line 194 def start_server! @@__server__ = Server.new @@__server__.run! end
Public Instance Methods
merge_config!(options)
click to toggle source
合并配置
# File lib/swee/engine.rb, line 66 def merge_config! options @config.default_config! options end
require_user_appconfig()
click to toggle source
加载 app配置
# File lib/swee/engine.rb, line 60 def require_user_appconfig # require_relative './application' Lodder.app_require end