From 7d75d2aae6c5e7aeecb60da7b94f478c523358a1 Mon Sep 17 00:00:00 2001 From: gyanpgupta Date: Tue, 7 Jun 2022 16:46:26 +0530 Subject: [PATCH 1/2] update active record configuration after updation --- lib/hijacker.rb | 5 +++-- lib/hijacker/base_model.rb | 2 +- lib/hijacker/host.rb | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/hijacker.rb b/lib/hijacker.rb index 4fe998e..e0f5494 100644 --- a/lib/hijacker.rb +++ b/lib/hijacker.rb @@ -187,13 +187,14 @@ def self.root_config end def self.database_configurations - ActiveRecord::Base.configurations + ActiveRecord::Base.configurations = YAML.load(File.read('config/database.yml')) end # this should establish a connection to a database containing the bare minimum # for loading the app, usually a sessions table if using sql-based sessions. def self.establish_root_connection - ActiveRecord::Base.establish_connection('root') + @dbconfig = YAML.load(File.read('config/database.yml')) + ActiveRecord::Base.establish_connection @dbconfig['root'] end def self.processing_sister_site? diff --git a/lib/hijacker/base_model.rb b/lib/hijacker/base_model.rb index f2abb42..08c3063 100644 --- a/lib/hijacker/base_model.rb +++ b/lib/hijacker/base_model.rb @@ -1,6 +1,6 @@ module Hijacker class BaseModel < ActiveRecord::Base - establish_connection('root') + establish_connection(:root) self.abstract_class = true end diff --git a/lib/hijacker/host.rb b/lib/hijacker/host.rb index b082e53..78828c2 100644 --- a/lib/hijacker/host.rb +++ b/lib/hijacker/host.rb @@ -1,6 +1,6 @@ class Hijacker::Host < Hijacker::BaseModel - validates_format_of :hostname, :with => /^(#{URI::REGEXP::PATTERN::HOST}|#{URI::REGEXP::PATTERN::IPV6ADDR})$/ + validates_format_of :hostname, :with => /\A(#{URI::REGEXP::PATTERN::HOST}|#{URI::REGEXP::PATTERN::IPV6ADDR})\z/ belongs_to :slave, class_name: "Hijacker::Host" end From e210c023e3e5fce6cc753a1771ca515d0603a53d Mon Sep 17 00:00:00 2001 From: gyanpgupta Date: Mon, 22 Aug 2022 14:56:02 +0530 Subject: [PATCH 2/2] fixed database not being fetched by hijacker --- lib/hijacker/database.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hijacker/database.rb b/lib/hijacker/database.rb index a6c8248..1a43579 100644 --- a/lib/hijacker/database.rb +++ b/lib/hijacker/database.rb @@ -59,7 +59,7 @@ def self.find_by_name(name) end def self.current - find(:first, :conditions => {:database => Hijacker.current_client}) + find_by(database: Hijacker.current_client) end # returns a string or nil