Commit 486d75137422490a34dd4a8d98786e3398995e1f

Authored by Braulio Bhavamitra
1 parent a349834a

application_record: Don't use it inside lib

This fix the development reloads
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
... ... @@ -122,4 +122,4 @@ module Customizable
122 122 end
123 123 end
124 124  
125   -ApplicationRecord.send :include, Customizable
  125 +ActiveRecord::Base.include Customizable
... ...
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
... ... @@ -35,4 +35,4 @@ module ActsAsHavingBoxes
35 35  
36 36 end
37 37  
38   -ApplicationRecord.extend ActsAsHavingBoxes::ClassMethods
  38 +ActiveRecord::Base.extend ActsAsHavingBoxes::ClassMethods
... ...
lib/acts_as_having_image.rb
... ... @@ -23,5 +23,5 @@ module ActsAsHavingImage
23 23  
24 24 end
25 25  
26   -ApplicationRecord.extend ActsAsHavingImage::ClassMethods
  26 +ActiveRecord::Base.extend ActsAsHavingImage::ClassMethods
27 27  
... ...
lib/acts_as_having_posts.rb
... ... @@ -47,5 +47,5 @@ module ActsAsHavingPosts
47 47  
48 48 end
49 49  
50   -ApplicationRecord.extend ActsAsHavingPosts::ClassMethods
  50 +ActiveRecord::Base.extend ActsAsHavingPosts::ClassMethods
51 51  
... ...
lib/acts_as_having_settings.rb
... ... @@ -87,5 +87,5 @@ module ActsAsHavingSettings
87 87  
88 88 end
89 89  
90   -ApplicationRecord.extend ActsAsHavingSettings::ClassMethods
  90 +ActiveRecord::Base.extend ActsAsHavingSettings::ClassMethods
91 91  
... ...
lib/code_numbering.rb
... ... @@ -55,4 +55,4 @@ module CodeNumbering
55 55 end
56 56 end
57 57  
58   -ApplicationRecord.extend CodeNumbering::ClassMethods
  58 +ActiveRecord::Base.extend CodeNumbering::ClassMethods
... ...
lib/delayed_attachment_fu.rb
... ... @@ -52,5 +52,5 @@ module DelayedAttachmentFu
52 52 end
53 53 end
54 54  
55   -ApplicationRecord.extend DelayedAttachmentFu::ClassMethods
  55 +ActiveRecord::Base.extend DelayedAttachmentFu::ClassMethods
56 56  
... ...
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
... ... @@ -69,5 +69,5 @@ module SplitDatetime
69 69 end
70 70  
71 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 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
... ... @@ -10,4 +10,4 @@ module UploadSanitizer
10 10 end
11 11 end
12 12  
13   -ApplicationRecord.send :include, UploadSanitizer
  13 +ActiveRecord::Base.send :include, UploadSanitizer
... ...