s|establish_connection|connect|g
This commit is contained in:
parent
27ce4251ac
commit
4f162796b0
12 changed files with 29 additions and 15 deletions
|
@ -21,7 +21,7 @@ class Twenty::Command::Connect < Twenty::Command
|
|||
private
|
||||
|
||||
def run_command(options)
|
||||
path = File.realpath(options.path ? options.path : Dir.getwd)
|
||||
path = File.realpath(options.path || Dir.getwd)
|
||||
if File.exist?(path)
|
||||
require_models!
|
||||
project = Twenty::Project.create(
|
||||
|
|
|
@ -20,7 +20,7 @@ class Twenty::Command::Disconnect < Twenty::Command
|
|||
private
|
||||
|
||||
def run_command(options)
|
||||
path = File.realpath(options.path ? options.path : Dir.getwd)
|
||||
path = File.realpath(options.path || Dir.getwd)
|
||||
require_models!
|
||||
Twenty::Project
|
||||
.where(path:)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Twenty::Command::Hook
|
||||
require_relative "hook/require_migration"
|
||||
require_relative "hook/sqlite_conn"
|
||||
|
|
|
@ -3,9 +3,16 @@
|
|||
module Twenty::Command::Hook
|
||||
module SQLiteConn
|
||||
def run_command(options)
|
||||
path = options.database || Twenty.default_database
|
||||
Twenty.establish_connection(path:)
|
||||
connect!(options)
|
||||
super(options)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def connect!(options)
|
||||
Twenty.connect(
|
||||
database: options.database || Twenty.default_database
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Twenty::Command::Option
|
||||
require_relative "option/database"
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Twenty::Command::Option
|
||||
module Database
|
||||
def self.included(mod)
|
||||
|
|
|
@ -42,22 +42,19 @@ module Twenty
|
|||
##
|
||||
# Establishes a database connection
|
||||
#
|
||||
# @param [String] path
|
||||
# The path to a SQLite database
|
||||
# @param [Hash] options
|
||||
# 'Sequel.connect' options
|
||||
#
|
||||
# @return [void]
|
||||
def self.establish_connection(path:)
|
||||
@db = Sequel.connect(
|
||||
adapter: "sqlite",
|
||||
database: path
|
||||
)
|
||||
def self.connect(options = {})
|
||||
@db = Sequel.connect({adapter: "sqlite"}.merge(options))
|
||||
end
|
||||
|
||||
##
|
||||
# @return [Sequel::Database::SQLite]
|
||||
# Returns a database object
|
||||
def self.db
|
||||
establish_connection unless @db
|
||||
connect unless @db
|
||||
@db
|
||||
end
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Twenty::Mixin
|
||||
require_relative "mixin/colorable"
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Twenty
|
||||
class Milestone < Sequel::Model
|
||||
include Model
|
||||
|
|
Loading…
Reference in a new issue