From c1b3498e99f82d3fbbc876a9fb67b4b98d6abf80 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sat, 27 Apr 2024 03:33:04 -0300 Subject: [PATCH] Add Command#require_models! --- cli/lib/twenty/cli/command.rb | 6 ++++++ cli/lib/twenty/cli/command/connect.rb | 2 +- cli/lib/twenty/cli/command/console.rb | 2 +- cli/lib/twenty/cli/command/disconnect.rb | 2 +- cli/lib/twenty/cli/command/up.rb | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cli/lib/twenty/cli/command.rb b/cli/lib/twenty/cli/command.rb index cf67eba..b29fd56 100644 --- a/cli/lib/twenty/cli/command.rb +++ b/cli/lib/twenty/cli/command.rb @@ -16,4 +16,10 @@ class Twenty::Command < Cmd require_relative "command/disconnect" require_relative "command/migrate" require_relative "command/console" + + private + + def require_models! + require "twenty/server/model" + end end diff --git a/cli/lib/twenty/cli/command/connect.rb b/cli/lib/twenty/cli/command/connect.rb index ede188e..c33bc29 100644 --- a/cli/lib/twenty/cli/command/connect.rb +++ b/cli/lib/twenty/cli/command/connect.rb @@ -21,9 +21,9 @@ class Twenty::Command::Connect < Twenty::Command private def run_command(options) - require "twenty/server/model" path = File.realpath(options.path ? options.path : Dir.getwd) if File.exist?(path) + require_models! project = Twenty::Project.create( name: File.basename(path), path: diff --git a/cli/lib/twenty/cli/command/console.rb b/cli/lib/twenty/cli/command/console.rb index e6e0189..f19669b 100644 --- a/cli/lib/twenty/cli/command/console.rb +++ b/cli/lib/twenty/cli/command/console.rb @@ -24,7 +24,7 @@ class Twenty::Command::Console < Twenty::Command private def run_command(options) - require "twenty/server/model" + require_models! require "irb" TOPLEVEL_BINDING.irb end diff --git a/cli/lib/twenty/cli/command/disconnect.rb b/cli/lib/twenty/cli/command/disconnect.rb index 1aa2084..0ea4724 100644 --- a/cli/lib/twenty/cli/command/disconnect.rb +++ b/cli/lib/twenty/cli/command/disconnect.rb @@ -19,8 +19,8 @@ class Twenty::Command::Disconnect < Twenty::Command private def run_command(options) - require "twenty/server/model" path = File.realpath(options.path ? options.path : Dir.getwd) + require_models! Twenty::Project .where(path:) .first! diff --git a/cli/lib/twenty/cli/command/up.rb b/cli/lib/twenty/cli/command/up.rb index 3144835..db00888 100644 --- a/cli/lib/twenty/cli/command/up.rb +++ b/cli/lib/twenty/cli/command/up.rb @@ -36,7 +36,7 @@ class Twenty::Command::Up < Twenty::Command private def run_command(options) - require "twenty/server/model" + require_models! File.binwrite(pid, Process.pid.to_s) thr = Twenty::Rack.server(options).start thr.join