From 486d75137422490a34dd4a8d98786e3398995e1f Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Sat, 14 May 2016 10:49:36 -0300 Subject: [PATCH] application_record: Don't use it inside lib --- app/models/application_record.rb | 5 +---- lib/acts_as_customizable.rb | 2 +- lib/acts_as_filesystem.rb | 4 ++-- lib/acts_as_having_boxes.rb | 2 +- lib/acts_as_having_image.rb | 2 +- lib/acts_as_having_posts.rb | 2 +- lib/acts_as_having_settings.rb | 2 +- lib/code_numbering.rb | 2 +- lib/delayed_attachment_fu.rb | 2 +- lib/noosfero/multi_tenancy.rb | 6 ++---- lib/noosfero/unicorn.rb | 4 ++-- lib/postgresql_attachment_fu.rb | 4 ++-- lib/split_datetime.rb | 2 +- lib/tasks/backup.rake | 2 +- lib/tasks/multitenancy.rake | 6 +++--- lib/upload_sanitizer.rb | 2 +- 16 files changed, 22 insertions(+), 27 deletions(-) diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 0abc9e2..db23de6 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -2,9 +2,6 @@ class ApplicationRecord < ActiveRecord::Base self.abstract_class = true - def self.postgresql? - self.connection.adapter_name == 'PostgreSQL' - end # an ActionView instance for rendering views on models def self.action_view @@ -25,7 +22,7 @@ class ApplicationRecord < ActiveRecord::Base alias :meta_cache_key :cache_key def cache_key key = [Noosfero::VERSION, meta_cache_key] - key.unshift(ApplicationRecord.connection.schema_search_path) if ApplicationRecord.postgresql? + key.unshift ApplicationRecord.connection.schema_search_path key.join('/') end diff --git a/lib/acts_as_customizable.rb b/lib/acts_as_customizable.rb index 9016bbb..c9c58b3 100644 --- a/lib/acts_as_customizable.rb +++ b/lib/acts_as_customizable.rb @@ -122,4 +122,4 @@ module Customizable end end -ApplicationRecord.send :include, Customizable +ActiveRecord::Base.include Customizable diff --git a/lib/acts_as_filesystem.rb b/lib/acts_as_filesystem.rb index 36406c6..77d022f 100644 --- a/lib/acts_as_filesystem.rb +++ b/lib/acts_as_filesystem.rb @@ -33,7 +33,7 @@ module ActsAsFileSystem module ClassMethods def build_ancestry(parent_id = nil, ancestry = '') - ApplicationRecord.transaction do + ActiveRecord::Base.transaction do self.base_class.where(parent_id: parent_id).each do |node| node.update_column :ancestry, ancestry @@ -263,5 +263,5 @@ module ActsAsFileSystem end end -ApplicationRecord.extend ActsAsFileSystem::ActsMethods +ActiveRecord::Base.extend ActsAsFileSystem::ActsMethods diff --git a/lib/acts_as_having_boxes.rb b/lib/acts_as_having_boxes.rb index 319c7a1..10b3ee6 100644 --- a/lib/acts_as_having_boxes.rb +++ b/lib/acts_as_having_boxes.rb @@ -35,4 +35,4 @@ module ActsAsHavingBoxes end -ApplicationRecord.extend ActsAsHavingBoxes::ClassMethods +ActiveRecord::Base.extend ActsAsHavingBoxes::ClassMethods diff --git a/lib/acts_as_having_image.rb b/lib/acts_as_having_image.rb index ba89d42..d6eaf68 100644 --- a/lib/acts_as_having_image.rb +++ b/lib/acts_as_having_image.rb @@ -23,5 +23,5 @@ module ActsAsHavingImage end -ApplicationRecord.extend ActsAsHavingImage::ClassMethods +ActiveRecord::Base.extend ActsAsHavingImage::ClassMethods diff --git a/lib/acts_as_having_posts.rb b/lib/acts_as_having_posts.rb index 2d51c0f..f34df3c 100644 --- a/lib/acts_as_having_posts.rb +++ b/lib/acts_as_having_posts.rb @@ -47,5 +47,5 @@ module ActsAsHavingPosts end -ApplicationRecord.extend ActsAsHavingPosts::ClassMethods +ActiveRecord::Base.extend ActsAsHavingPosts::ClassMethods diff --git a/lib/acts_as_having_settings.rb b/lib/acts_as_having_settings.rb index dc22d59..c43a53f 100644 --- a/lib/acts_as_having_settings.rb +++ b/lib/acts_as_having_settings.rb @@ -87,5 +87,5 @@ module ActsAsHavingSettings end -ApplicationRecord.extend ActsAsHavingSettings::ClassMethods +ActiveRecord::Base.extend ActsAsHavingSettings::ClassMethods diff --git a/lib/code_numbering.rb b/lib/code_numbering.rb index b980a59..843cc33 100644 --- a/lib/code_numbering.rb +++ b/lib/code_numbering.rb @@ -55,4 +55,4 @@ module CodeNumbering end end -ApplicationRecord.extend CodeNumbering::ClassMethods +ActiveRecord::Base.extend CodeNumbering::ClassMethods diff --git a/lib/delayed_attachment_fu.rb b/lib/delayed_attachment_fu.rb index fc849bd..3e2c1a1 100644 --- a/lib/delayed_attachment_fu.rb +++ b/lib/delayed_attachment_fu.rb @@ -52,5 +52,5 @@ module DelayedAttachmentFu end end -ApplicationRecord.extend DelayedAttachmentFu::ClassMethods +ActiveRecord::Base.extend DelayedAttachmentFu::ClassMethods diff --git a/lib/noosfero/multi_tenancy.rb b/lib/noosfero/multi_tenancy.rb index f0f8c2b..b80a903 100644 --- a/lib/noosfero/multi_tenancy.rb +++ b/lib/noosfero/multi_tenancy.rb @@ -12,14 +12,12 @@ module Noosfero def self.db_by_host=(host) if host != @db_by_host @db_by_host = host - ApplicationRecord.connection.schema_search_path = self.mapping[host] + ActiveRecord::Base.connection.schema_search_path = self.mapping[host] end end def self.setup!(host) - if Noosfero::MultiTenancy.on? and ApplicationRecord.postgresql? - Noosfero::MultiTenancy.db_by_host = host - end + Noosfero::MultiTenancy.db_by_host = host end class Middleware diff --git a/lib/noosfero/unicorn.rb b/lib/noosfero/unicorn.rb index f740e82..666e44d 100644 --- a/lib/noosfero/unicorn.rb +++ b/lib/noosfero/unicorn.rb @@ -7,11 +7,11 @@ GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly = true before_fork do |server, worker| - ApplicationRecord.connection.disconnect! if defined?(ApplicationRecord) + ActiveRecord::Base.connection.disconnect! if defined? ActiveRecord::Base end after_fork do |server, worker| - ApplicationRecord.establish_connection if defined?(ApplicationRecord) + ActiveRecord::Base.establish_connection if defined? ActiveRecord::Base end # load local configuration file, if it exists diff --git a/lib/postgresql_attachment_fu.rb b/lib/postgresql_attachment_fu.rb index cf4a4f7..1027358 100644 --- a/lib/postgresql_attachment_fu.rb +++ b/lib/postgresql_attachment_fu.rb @@ -9,12 +9,12 @@ module PostgresqlAttachmentFu module InstanceMethods def full_filename(thumbnail = nil) file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s - file_system_path = File.join(file_system_path, ApplicationRecord.connection.schema_search_path) if ApplicationRecord.postgresql? and Noosfero::MultiTenancy.on? + file_system_path = File.join(file_system_path, ActiveRecord::Base.connection.schema_search_path) if Noosfero::MultiTenancy.on? Rails.root.join(file_system_path, *partitioned_path(thumbnail_name_for(thumbnail))).to_s end end end -ApplicationRecord.extend PostgresqlAttachmentFu::ClassMethods +ActiveRecord::Base.extend PostgresqlAttachmentFu::ClassMethods diff --git a/lib/split_datetime.rb b/lib/split_datetime.rb index 5d27c08..7516469 100644 --- a/lib/split_datetime.rb +++ b/lib/split_datetime.rb @@ -69,5 +69,5 @@ module SplitDatetime end Class.extend SplitDatetime::SplitMethods -ApplicationRecord.extend SplitDatetime::SplitMethods +ActiveRecord::Base.extend SplitDatetime::SplitMethods diff --git a/lib/tasks/backup.rake b/lib/tasks/backup.rake index 59f2bd6..c5f7320 100644 --- a/lib/tasks/backup.rake +++ b/lib/tasks/backup.rake @@ -115,7 +115,7 @@ end desc 'Removes emails from database' task 'restore:remove_emails' => :environment do - connection = ApplicationRecord.connection + connection = ActiveRecord::Base.connection [ "UPDATE users SET email = concat('user', id, '@localhost.localdomain')", "UPDATE environments SET contact_email = concat('environment', id, '@localhost.localdomain')", diff --git a/lib/tasks/multitenancy.rake b/lib/tasks/multitenancy.rake index caad220..af646f4 100644 --- a/lib/tasks/multitenancy.rake +++ b/lib/tasks/multitenancy.rake @@ -1,14 +1,14 @@ namespace :multitenancy do task :create => :environment do - db_envs = ApplicationRecord.configurations.keys.select{ |k| k.match(/_development$|_production$|_test$/) } + db_envs = ActiveRecord::Base.configurations.keys.select{ |k| k.match(/_development$|_production$|_test$/) } cd Rails.root.join('config', 'environments'), :verbose => true file_envs = Dir.glob "{*_development.rb,*_production.rb,*_test.rb}" (db_envs.map{ |e| e + '.rb' } - file_envs).each { |env| ln_s env.split('_').last, env } end task :remove => :environment do - db_envs = ApplicationRecord.configurations.keys.select{ |k| k.match(/_development$|_production$|_test$/) } + db_envs = ActiveRecord::Base.configurations.keys.select{ |k| k.match(/_development$|_production$|_test$/) } cd Rails.root.join('config', 'environments'), :verbose => true file_envs = Dir.glob "{*_development.rb,*_production.rb,*_test.rb}" (file_envs - db_envs.map{ |e| e + '.rb' }).each { |env| safe_unlink env } @@ -19,7 +19,7 @@ end namespace :db do task :migrate_other_environments => :environment do - envs = ApplicationRecord.configurations.keys.select{ |k| k.match(/_#{Rails.env}$/) } + envs = ActiveRecord::Base.configurations.keys.select{ |k| k.match(/_#{Rails.env}$/) } envs.each do |e| puts "*** Migrating #{e}" if Rake.application.options.trace system "rake db:migrate RAILS_ENV=#{e} SCHEMA=/dev/null" diff --git a/lib/upload_sanitizer.rb b/lib/upload_sanitizer.rb index 05a45f7..445decd 100644 --- a/lib/upload_sanitizer.rb +++ b/lib/upload_sanitizer.rb @@ -10,4 +10,4 @@ module UploadSanitizer end end -ApplicationRecord.send :include, UploadSanitizer +ActiveRecord::Base.send :include, UploadSanitizer -- libgit2 0.21.2