Class: Swee::Engine
Constant Summary collapse
- @@__instance__ =
> 实例
nil
- @@__server__ =
> 服务器
nil
Class Method Summary collapse
-
.boot!(argv) ⇒ Object
启动服务.
- .cache_file_mtime ⇒ Object
-
.config ⇒ Object
配置实例.
-
.instance ⇒ Object
当前实例.
-
.parse_cmd(cmd, options) ⇒ Object
解析命令 c -> 命令行 s -> 启动服务.
-
.parse_options ⇒ Object
命令行解析.
-
.require_files ⇒ Object
加载全部文件.
-
.restart_server! ⇒ Object
重启服务器.
-
.server ⇒ Object
服务器实例.
-
.start_server! ⇒ Object
启动服务器.
Instance Method Summary collapse
-
#initialize(options) ⇒ Engine
constructor
A new instance of Engine.
-
#merge_config!(options) ⇒ Object
合并配置.
-
#require_user_appconfig ⇒ Object
加载 app配置.
Constructor Details
#initialize(options) ⇒ Engine
Returns a new instance of Engine.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/swee/engine.rb', line 49 def initialize # 初始化配置 @config = Swee.init_config # 读取用户配置 require_user_appconfig # 合并配置 merge_config! end |
Class Method Details
.boot!(argv) ⇒ Object
启动服务
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/swee/engine.rb', line 113 def boot! argv cmd = argv.shift || "s" = .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 parse_cmd cmd, end end |
.cache_file_mtime ⇒ Object
181 182 183 |
# File 'lib/swee/engine.rb', line 181 def cache_file_mtime Lodder.cache_file_mtime end |
.config ⇒ Object
配置实例
77 78 79 |
# File 'lib/swee/engine.rb', line 77 def config instance.send :config end |
.instance ⇒ Object
当前实例
73 74 75 |
# File 'lib/swee/engine.rb', line 73 def instance @@__instance__ end |
.parse_cmd(cmd, options) ⇒ Object
解析命令 c -> 命令行 s -> 启动服务
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/swee/engine.rb', line 140 def parse_cmd cmd, case cmd when "c" # => 命令行模式 require 'irb' IRB.start when "s" # => 启动服务器 start_server! else raise "命令不合法" end end |
.parse_options ⇒ Object
命令行解析
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/swee/engine.rb', line 94 def = {} OptionParser.new do |opts| opts. = "swee框架使用参数如下" opts.on("-p", "--port PORT", Integer, "端口 (默认: 3000)") do |port| [:listen] = port end opts.on("-e", "--env ENV", "环境 development 或 production (默认为development)") do |e| [:env] = e end end.parse! end |
.require_files ⇒ Object
加载全部文件
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/swee/engine.rb', line 153 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.('./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! ⇒ Object
重启服务器
186 187 188 189 190 191 192 |
# File 'lib/swee/engine.rb', line 186 def restart_server! @@__server__ = nil GC.start require_files cache_file_mtime start_server! end |
Instance Method Details
#merge_config!(options) ⇒ Object
合并配置
67 68 69 |
# File 'lib/swee/engine.rb', line 67 def merge_config! @config.default_config! end |
#require_user_appconfig ⇒ Object
加载 app配置
61 62 63 64 |
# File 'lib/swee/engine.rb', line 61 def require_user_appconfig # require_relative './application' Lodder.app_require end |