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 | 2 | |
3 | 3 | self.abstract_class = true |
4 | 4 | |
5 | - def self.postgresql? | |
6 | - self.connection.adapter_name == 'PostgreSQL' | |
7 | - end | |
8 | 5 | |
9 | 6 | # an ActionView instance for rendering views on models |
10 | 7 | def self.action_view |
... | ... | @@ -25,7 +22,7 @@ class ApplicationRecord < ActiveRecord::Base |
25 | 22 | alias :meta_cache_key :cache_key |
26 | 23 | def cache_key |
27 | 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 | 26 | key.join('/') |
30 | 27 | end |
31 | 28 | ... | ... |
lib/acts_as_customizable.rb
lib/acts_as_filesystem.rb
... | ... | @@ -33,7 +33,7 @@ module ActsAsFileSystem |
33 | 33 | module ClassMethods |
34 | 34 | |
35 | 35 | def build_ancestry(parent_id = nil, ancestry = '') |
36 | - ApplicationRecord.transaction do | |
36 | + ActiveRecord::Base.transaction do | |
37 | 37 | self.base_class.where(parent_id: parent_id).each do |node| |
38 | 38 | node.update_column :ancestry, ancestry |
39 | 39 | |
... | ... | @@ -263,5 +263,5 @@ module ActsAsFileSystem |
263 | 263 | end |
264 | 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 | 12 | def self.db_by_host=(host) |
13 | 13 | if host != @db_by_host |
14 | 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 | 16 | end |
17 | 17 | end |
18 | 18 | |
19 | 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 | 21 | end |
24 | 22 | |
25 | 23 | class Middleware | ... | ... |
lib/noosfero/unicorn.rb
... | ... | @@ -7,11 +7,11 @@ GC.respond_to?(:copy_on_write_friendly=) and |
7 | 7 | GC.copy_on_write_friendly = true |
8 | 8 | |
9 | 9 | before_fork do |server, worker| |
10 | - ApplicationRecord.connection.disconnect! if defined?(ApplicationRecord) | |
10 | + ActiveRecord::Base.connection.disconnect! if defined? ActiveRecord::Base | |
11 | 11 | end |
12 | 12 | |
13 | 13 | after_fork do |server, worker| |
14 | - ApplicationRecord.establish_connection if defined?(ApplicationRecord) | |
14 | + ActiveRecord::Base.establish_connection if defined? ActiveRecord::Base | |
15 | 15 | end |
16 | 16 | |
17 | 17 | # load local configuration file, if it exists | ... | ... |
lib/postgresql_attachment_fu.rb
... | ... | @@ -9,12 +9,12 @@ module PostgresqlAttachmentFu |
9 | 9 | module InstanceMethods |
10 | 10 | def full_filename(thumbnail = nil) |
11 | 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 | 13 | Rails.root.join(file_system_path, *partitioned_path(thumbnail_name_for(thumbnail))).to_s |
14 | 14 | end |
15 | 15 | end |
16 | 16 | |
17 | 17 | end |
18 | 18 | |
19 | -ApplicationRecord.extend PostgresqlAttachmentFu::ClassMethods | |
19 | +ActiveRecord::Base.extend PostgresqlAttachmentFu::ClassMethods | |
20 | 20 | ... | ... |
lib/split_datetime.rb
lib/tasks/backup.rake
... | ... | @@ -115,7 +115,7 @@ end |
115 | 115 | |
116 | 116 | desc 'Removes emails from database' |
117 | 117 | task 'restore:remove_emails' => :environment do |
118 | - connection = ApplicationRecord.connection | |
118 | + connection = ActiveRecord::Base.connection | |
119 | 119 | [ |
120 | 120 | "UPDATE users SET email = concat('user', id, '@localhost.localdomain')", |
121 | 121 | "UPDATE environments SET contact_email = concat('environment', id, '@localhost.localdomain')", | ... | ... |
lib/tasks/multitenancy.rake
1 | 1 | namespace :multitenancy do |
2 | 2 | |
3 | 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 | 5 | cd Rails.root.join('config', 'environments'), :verbose => true |
6 | 6 | file_envs = Dir.glob "{*_development.rb,*_production.rb,*_test.rb}" |
7 | 7 | (db_envs.map{ |e| e + '.rb' } - file_envs).each { |env| ln_s env.split('_').last, env } |
8 | 8 | end |
9 | 9 | |
10 | 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 | 12 | cd Rails.root.join('config', 'environments'), :verbose => true |
13 | 13 | file_envs = Dir.glob "{*_development.rb,*_production.rb,*_test.rb}" |
14 | 14 | (file_envs - db_envs.map{ |e| e + '.rb' }).each { |env| safe_unlink env } |
... | ... | @@ -19,7 +19,7 @@ end |
19 | 19 | namespace :db do |
20 | 20 | |
21 | 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 | 23 | envs.each do |e| |
24 | 24 | puts "*** Migrating #{e}" if Rake.application.options.trace |
25 | 25 | system "rake db:migrate RAILS_ENV=#{e} SCHEMA=/dev/null" | ... | ... |
lib/upload_sanitizer.rb