Commit 486d75137422490a34dd4a8d98786e3398995e1f
1 parent
a349834a
Exists in
ratings_minor_fixes
and in
4 other branches
application_record: Don't use it inside lib
This fix the development reloads
Showing
16 changed files
with
22 additions
and
27 deletions
Show diff stats
app/models/application_record.rb
@@ -2,9 +2,6 @@ class ApplicationRecord < ActiveRecord::Base | @@ -2,9 +2,6 @@ class ApplicationRecord < ActiveRecord::Base | ||
2 | 2 | ||
3 | self.abstract_class = true | 3 | self.abstract_class = true |
4 | 4 | ||
5 | - def self.postgresql? | ||
6 | - self.connection.adapter_name == 'PostgreSQL' | ||
7 | - end | ||
8 | 5 | ||
9 | # an ActionView instance for rendering views on models | 6 | # an ActionView instance for rendering views on models |
10 | def self.action_view | 7 | def self.action_view |
@@ -25,7 +22,7 @@ class ApplicationRecord < ActiveRecord::Base | @@ -25,7 +22,7 @@ class ApplicationRecord < ActiveRecord::Base | ||
25 | alias :meta_cache_key :cache_key | 22 | alias :meta_cache_key :cache_key |
26 | def cache_key | 23 | def cache_key |
27 | key = [Noosfero::VERSION, meta_cache_key] | 24 | key = [Noosfero::VERSION, meta_cache_key] |
28 | - key.unshift(ApplicationRecord.connection.schema_search_path) if ApplicationRecord.postgresql? | 25 | + key.unshift ApplicationRecord.connection.schema_search_path |
29 | key.join('/') | 26 | key.join('/') |
30 | end | 27 | end |
31 | 28 |
lib/acts_as_customizable.rb
lib/acts_as_filesystem.rb
@@ -33,7 +33,7 @@ module ActsAsFileSystem | @@ -33,7 +33,7 @@ module ActsAsFileSystem | ||
33 | module ClassMethods | 33 | module ClassMethods |
34 | 34 | ||
35 | def build_ancestry(parent_id = nil, ancestry = '') | 35 | def build_ancestry(parent_id = nil, ancestry = '') |
36 | - ApplicationRecord.transaction do | 36 | + ActiveRecord::Base.transaction do |
37 | self.base_class.where(parent_id: parent_id).each do |node| | 37 | self.base_class.where(parent_id: parent_id).each do |node| |
38 | node.update_column :ancestry, ancestry | 38 | node.update_column :ancestry, ancestry |
39 | 39 | ||
@@ -263,5 +263,5 @@ module ActsAsFileSystem | @@ -263,5 +263,5 @@ module ActsAsFileSystem | ||
263 | end | 263 | end |
264 | end | 264 | end |
265 | 265 | ||
266 | -ApplicationRecord.extend ActsAsFileSystem::ActsMethods | 266 | +ActiveRecord::Base.extend ActsAsFileSystem::ActsMethods |
267 | 267 |
lib/acts_as_having_boxes.rb
lib/acts_as_having_image.rb
lib/acts_as_having_posts.rb
lib/acts_as_having_settings.rb
lib/code_numbering.rb
lib/delayed_attachment_fu.rb
lib/noosfero/multi_tenancy.rb
@@ -12,14 +12,12 @@ module Noosfero | @@ -12,14 +12,12 @@ module Noosfero | ||
12 | def self.db_by_host=(host) | 12 | def self.db_by_host=(host) |
13 | if host != @db_by_host | 13 | if host != @db_by_host |
14 | @db_by_host = host | 14 | @db_by_host = host |
15 | - ApplicationRecord.connection.schema_search_path = self.mapping[host] | 15 | + ActiveRecord::Base.connection.schema_search_path = self.mapping[host] |
16 | end | 16 | end |
17 | end | 17 | end |
18 | 18 | ||
19 | def self.setup!(host) | 19 | def self.setup!(host) |
20 | - if Noosfero::MultiTenancy.on? and ApplicationRecord.postgresql? | ||
21 | - Noosfero::MultiTenancy.db_by_host = host | ||
22 | - end | 20 | + Noosfero::MultiTenancy.db_by_host = host |
23 | end | 21 | end |
24 | 22 | ||
25 | class Middleware | 23 | class Middleware |
lib/noosfero/unicorn.rb
@@ -7,11 +7,11 @@ GC.respond_to?(:copy_on_write_friendly=) and | @@ -7,11 +7,11 @@ GC.respond_to?(:copy_on_write_friendly=) and | ||
7 | GC.copy_on_write_friendly = true | 7 | GC.copy_on_write_friendly = true |
8 | 8 | ||
9 | before_fork do |server, worker| | 9 | before_fork do |server, worker| |
10 | - ApplicationRecord.connection.disconnect! if defined?(ApplicationRecord) | 10 | + ActiveRecord::Base.connection.disconnect! if defined? ActiveRecord::Base |
11 | end | 11 | end |
12 | 12 | ||
13 | after_fork do |server, worker| | 13 | after_fork do |server, worker| |
14 | - ApplicationRecord.establish_connection if defined?(ApplicationRecord) | 14 | + ActiveRecord::Base.establish_connection if defined? ActiveRecord::Base |
15 | end | 15 | end |
16 | 16 | ||
17 | # load local configuration file, if it exists | 17 | # load local configuration file, if it exists |
lib/postgresql_attachment_fu.rb
@@ -9,12 +9,12 @@ module PostgresqlAttachmentFu | @@ -9,12 +9,12 @@ module PostgresqlAttachmentFu | ||
9 | module InstanceMethods | 9 | module InstanceMethods |
10 | def full_filename(thumbnail = nil) | 10 | def full_filename(thumbnail = nil) |
11 | file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s | 11 | file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s |
12 | - file_system_path = File.join(file_system_path, ApplicationRecord.connection.schema_search_path) if ApplicationRecord.postgresql? and Noosfero::MultiTenancy.on? | 12 | + file_system_path = File.join(file_system_path, ActiveRecord::Base.connection.schema_search_path) if Noosfero::MultiTenancy.on? |
13 | Rails.root.join(file_system_path, *partitioned_path(thumbnail_name_for(thumbnail))).to_s | 13 | Rails.root.join(file_system_path, *partitioned_path(thumbnail_name_for(thumbnail))).to_s |
14 | end | 14 | end |
15 | end | 15 | end |
16 | 16 | ||
17 | end | 17 | end |
18 | 18 | ||
19 | -ApplicationRecord.extend PostgresqlAttachmentFu::ClassMethods | 19 | +ActiveRecord::Base.extend PostgresqlAttachmentFu::ClassMethods |
20 | 20 |
lib/split_datetime.rb
@@ -69,5 +69,5 @@ module SplitDatetime | @@ -69,5 +69,5 @@ module SplitDatetime | ||
69 | end | 69 | end |
70 | 70 | ||
71 | Class.extend SplitDatetime::SplitMethods | 71 | Class.extend SplitDatetime::SplitMethods |
72 | -ApplicationRecord.extend SplitDatetime::SplitMethods | 72 | +ActiveRecord::Base.extend SplitDatetime::SplitMethods |
73 | 73 |
lib/tasks/backup.rake
@@ -115,7 +115,7 @@ end | @@ -115,7 +115,7 @@ end | ||
115 | 115 | ||
116 | desc 'Removes emails from database' | 116 | desc 'Removes emails from database' |
117 | task 'restore:remove_emails' => :environment do | 117 | task 'restore:remove_emails' => :environment do |
118 | - connection = ApplicationRecord.connection | 118 | + connection = ActiveRecord::Base.connection |
119 | [ | 119 | [ |
120 | "UPDATE users SET email = concat('user', id, '@localhost.localdomain')", | 120 | "UPDATE users SET email = concat('user', id, '@localhost.localdomain')", |
121 | "UPDATE environments SET contact_email = concat('environment', id, '@localhost.localdomain')", | 121 | "UPDATE environments SET contact_email = concat('environment', id, '@localhost.localdomain')", |
lib/tasks/multitenancy.rake
1 | namespace :multitenancy do | 1 | namespace :multitenancy do |
2 | 2 | ||
3 | task :create => :environment do | 3 | task :create => :environment do |
4 | - db_envs = ApplicationRecord.configurations.keys.select{ |k| k.match(/_development$|_production$|_test$/) } | 4 | + db_envs = ActiveRecord::Base.configurations.keys.select{ |k| k.match(/_development$|_production$|_test$/) } |
5 | cd Rails.root.join('config', 'environments'), :verbose => true | 5 | cd Rails.root.join('config', 'environments'), :verbose => true |
6 | file_envs = Dir.glob "{*_development.rb,*_production.rb,*_test.rb}" | 6 | file_envs = Dir.glob "{*_development.rb,*_production.rb,*_test.rb}" |
7 | (db_envs.map{ |e| e + '.rb' } - file_envs).each { |env| ln_s env.split('_').last, env } | 7 | (db_envs.map{ |e| e + '.rb' } - file_envs).each { |env| ln_s env.split('_').last, env } |
8 | end | 8 | end |
9 | 9 | ||
10 | task :remove => :environment do | 10 | task :remove => :environment do |
11 | - db_envs = ApplicationRecord.configurations.keys.select{ |k| k.match(/_development$|_production$|_test$/) } | 11 | + db_envs = ActiveRecord::Base.configurations.keys.select{ |k| k.match(/_development$|_production$|_test$/) } |
12 | cd Rails.root.join('config', 'environments'), :verbose => true | 12 | cd Rails.root.join('config', 'environments'), :verbose => true |
13 | file_envs = Dir.glob "{*_development.rb,*_production.rb,*_test.rb}" | 13 | file_envs = Dir.glob "{*_development.rb,*_production.rb,*_test.rb}" |
14 | (file_envs - db_envs.map{ |e| e + '.rb' }).each { |env| safe_unlink env } | 14 | (file_envs - db_envs.map{ |e| e + '.rb' }).each { |env| safe_unlink env } |
@@ -19,7 +19,7 @@ end | @@ -19,7 +19,7 @@ end | ||
19 | namespace :db do | 19 | namespace :db do |
20 | 20 | ||
21 | task :migrate_other_environments => :environment do | 21 | task :migrate_other_environments => :environment do |
22 | - envs = ApplicationRecord.configurations.keys.select{ |k| k.match(/_#{Rails.env}$/) } | 22 | + envs = ActiveRecord::Base.configurations.keys.select{ |k| k.match(/_#{Rails.env}$/) } |
23 | envs.each do |e| | 23 | envs.each do |e| |
24 | puts "*** Migrating #{e}" if Rake.application.options.trace | 24 | puts "*** Migrating #{e}" if Rake.application.options.trace |
25 | system "rake db:migrate RAILS_ENV=#{e} SCHEMA=/dev/null" | 25 | system "rake db:migrate RAILS_ENV=#{e} SCHEMA=/dev/null" |
lib/upload_sanitizer.rb