Add Command#require_models!

This commit is contained in:
0x1eef 2024-04-27 03:33:04 -03:00
parent dc0093c7d9
commit c1b3498e99
5 changed files with 10 additions and 4 deletions

View file

@ -16,4 +16,10 @@ class Twenty::Command < Cmd
require_relative "command/disconnect" require_relative "command/disconnect"
require_relative "command/migrate" require_relative "command/migrate"
require_relative "command/console" require_relative "command/console"
private
def require_models!
require "twenty/server/model"
end
end end

View file

@ -21,9 +21,9 @@ class Twenty::Command::Connect < Twenty::Command
private private
def run_command(options) def run_command(options)
require "twenty/server/model"
path = File.realpath(options.path ? options.path : Dir.getwd) path = File.realpath(options.path ? options.path : Dir.getwd)
if File.exist?(path) if File.exist?(path)
require_models!
project = Twenty::Project.create( project = Twenty::Project.create(
name: File.basename(path), name: File.basename(path),
path: path:

View file

@ -24,7 +24,7 @@ class Twenty::Command::Console < Twenty::Command
private private
def run_command(options) def run_command(options)
require "twenty/server/model" require_models!
require "irb" require "irb"
TOPLEVEL_BINDING.irb TOPLEVEL_BINDING.irb
end end

View file

@ -19,8 +19,8 @@ class Twenty::Command::Disconnect < Twenty::Command
private private
def run_command(options) def run_command(options)
require "twenty/server/model"
path = File.realpath(options.path ? options.path : Dir.getwd) path = File.realpath(options.path ? options.path : Dir.getwd)
require_models!
Twenty::Project Twenty::Project
.where(path:) .where(path:)
.first! .first!

View file

@ -36,7 +36,7 @@ class Twenty::Command::Up < Twenty::Command
private private
def run_command(options) def run_command(options)
require "twenty/server/model" require_models!
File.binwrite(pid, Process.pid.to_s) File.binwrite(pid, Process.pid.to_s)
thr = Twenty::Rack.server(options).start thr = Twenty::Rack.server(options).start
thr.join thr.join