Commit da1968e4352a8ce4628b75c2872f8e84430e0587

Authored by Braulio Bhavamitra
1 parent 486d7513

Cleanup initialization

app/models/application_record.rb
1 class ApplicationRecord < ActiveRecord::Base 1 class ApplicationRecord < ActiveRecord::Base
2 2
3 - self.abstract_class = true  
4 - 3 + self.abstract_class = true
  4 + self.store_full_sti_class = true
5 5
6 # an ActionView instance for rendering views on models 6 # an ActionView instance for rendering views on models
7 def self.action_view 7 def self.action_view
config/application.rb
1 -require File.expand_path('../boot', __FILE__) 1 +require_relative 'boot'
2 2
3 require 'rails/all' 3 require 'rails/all'
4 require 'active_support/dependencies' 4 require 'active_support/dependencies'
5 5
6 -# FIXME this silences the warnings about Rails 2.3-style plugins under  
7 -# vendor/plugins, which are deprecated. Hiding those warnings makes it easier  
8 -# to work for now, but we should really look at putting those plugins away. 6 +# Silence Rails 5 deprecation warnings
9 ActiveSupport::Deprecation.silenced = true 7 ActiveSupport::Deprecation.silenced = true
10 8
11 Bundler.require(:default, :assets, Rails.env) 9 Bundler.require(:default, :assets, Rails.env)
  10 +$: << File.expand_path('../lib', File.dirname(__FILE__))
  11 +
  12 +require_dependency 'noosfero'
  13 +require_dependency 'noosfero/plugin'
  14 +require_dependency 'noosfero/multi_tenancy'
12 15
13 module Noosfero 16 module Noosfero
14 class Application < Rails::Application 17 class Application < Rails::Application
15 18
16 - require 'noosfero/plugin'  
17 -  
18 # The plugin xss_terminator(located in vendor/plugins/xss_terminator) and the helper 19 # The plugin xss_terminator(located in vendor/plugins/xss_terminator) and the helper
19 # SanitizeHelper(located in app/helpers/sanitize_helper.rb) use 20 # SanitizeHelper(located in app/helpers/sanitize_helper.rb) use
20 # ALLOWED_TAGS and ALLOWED_ATTRIBUTES to make a sanitize with html. 21 # ALLOWED_TAGS and ALLOWED_ATTRIBUTES to make a sanitize with html.
@@ -30,9 +31,6 @@ module Noosfero @@ -30,9 +31,6 @@ module Noosfero
30 config.action_view.sanitized_allowed_tags = ALLOWED_TAGS 31 config.action_view.sanitized_allowed_tags = ALLOWED_TAGS
31 config.action_view.sanitized_allowed_attributes = ALLOWED_ATTRIBUTES 32 config.action_view.sanitized_allowed_attributes = ALLOWED_ATTRIBUTES
32 33
33 - require 'noosfero/multi_tenancy'  
34 - config.middleware.use Noosfero::MultiTenancy::Middleware  
35 -  
36 config.action_controller.include_all_helpers = false 34 config.action_controller.include_all_helpers = false
37 35
38 # Settings in config/environments/* take precedence over those specified here. 36 # Settings in config/environments/* take precedence over those specified here.
@@ -40,10 +38,11 @@ module Noosfero @@ -40,10 +38,11 @@ module Noosfero
40 # -- all .rb files in that directory are automatically loaded. 38 # -- all .rb files in that directory are automatically loaded.
41 39
42 # Custom directories with classes and modules you want to be autoloadable. 40 # Custom directories with classes and modules you want to be autoloadable.
43 - config.autoload_paths += %W( #{config.root.join('app', 'sweepers')} )  
44 - config.autoload_paths += Dir["#{config.root}/lib"]  
45 - config.autoload_paths += Dir["#{config.root}/app/controllers/**/"]  
46 - config.autoload_paths += %W( #{config.root.join('test', 'mocks', Rails.env)} ) 41 + config.autoload_paths << config.root.join('lib')
  42 + config.autoload_paths << config.root.join('app/jobs')
  43 + config.autoload_paths << config.root.join('app/sweepers')
  44 + config.autoload_paths.concat Dir["#{config.root}/app/controllers/**/"]
  45 + config.autoload_paths << config.root.join('test', 'mocks', Rails.env)
47 46
48 # Only load the plugins named here, in the order given (default is alphabetical). 47 # Only load the plugins named here, in the order given (default is alphabetical).
49 # :all can be used as a placeholder for all plugins not explicitly named. 48 # :all can be used as a placeholder for all plugins not explicitly named.
@@ -119,7 +118,8 @@ module Noosfero @@ -119,7 +118,8 @@ module Noosfero
119 118
120 config.eager_load = true 119 config.eager_load = true
121 120
122 - Noosfero::Plugin.setup(config) 121 + config.middleware.use Noosfero::MultiTenancy::Middleware
123 122
  123 + Noosfero::Plugin.setup(config)
124 end 124 end
125 end 125 end
config/environment.rb
1 -# Load the rails application  
2 -require File.expand_path('../application', __FILE__) 1 +require_relative 'application'
3 2
4 -#FIXME Necessary hack to avoid the need of downgrading rubygems on rails 2.3.5  
5 -# http://stackoverflow.com/questions/5564251/uninitialized-constant-activesupportdependenciesmutex  
6 -require 'thread'  
7 -  
8 -# Uncomment below to force Rails into production mode when  
9 -# you don't control web/app server and can't set it the proper way  
10 -#ENV['RAILS_ENV'] ||= 'production'  
11 -  
12 -# extra directories for controllers organization  
13 -extra_controller_dirs = %w[  
14 -].map {|item| Rails.root.join(item) }  
15 -  
16 -# Add new inflection rules using the following format  
17 -# (all these examples are active by default):  
18 -# Inflector.inflections do |inflect|  
19 -# inflect.plural /^(ox)$/i, '\1en'  
20 -# inflect.singular /^(ox)en/i, '\1'  
21 -# inflect.irregular 'person', 'people'  
22 -# inflect.uncountable %w( fish sheep )  
23 -# end  
24 -  
25 -# Include your application configuration below  
26 -  
27 -ActiveRecord::Base.store_full_sti_class = true  
28 -  
29 -#FIXME: Probably act_as_taggable_on is not being loaded or this should be on another place  
30 -#Tag.hierarchical = true  
31 -  
32 -# several local libraries  
33 -require_dependency 'noosfero'  
34 -#FIXME: error when call lib/sqlite_extention  
35 -#require 'sqlite_extension' 3 +Noosfero::Application.initialize!
36 4
37 # load a local configuration if present, but not under test environment. 5 # load a local configuration if present, but not under test environment.
38 -if !['test', 'cucumber'].include?(ENV['RAILS_ENV']) 6 +if ENV['RAILS_ENV'].in? %w[test cucumber]
39 localconfigfile = Rails.root.join('config', 'local.rb') 7 localconfigfile = Rails.root.join('config', 'local.rb')
40 - if File.exists?(localconfigfile)  
41 - require localconfigfile  
42 - end 8 + require localconfigfile if File.exists? localconfigfile
43 end 9 end
44 10
45 -Noosfero::Application.initialize!  
config/initializers/00_dependencies.rb 0 → 100644
@@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
  1 +require 'pp'
  2 +
  3 +# third-party libraries
  4 +require 'will_paginate'
  5 +require 'will_paginate/array'
  6 +require 'nokogiri'
  7 +
  8 +# dependencies at vendor, firstly loaded on Gemfile
  9 +vendor = Dir.glob('vendor/{,plugins/}*') - ['vendor/plugins']
  10 +vendor.each do |dir|
  11 + init_rb = "#{Rails.root}/#{dir}/init.rb"
  12 + require init_rb if File.file? init_rb
  13 +end
  14 +
  15 +# extensions
  16 +require 'extensions'
  17 +
  18 +# locally-developed modules
  19 +require 'acts_as_filesystem'
  20 +require 'acts_as_having_settings'
  21 +require 'acts_as_having_boxes'
  22 +require 'acts_as_having_image'
  23 +require 'acts_as_having_posts'
  24 +require 'acts_as_customizable'
  25 +require 'route_if'
  26 +require 'maybe_add_http'
  27 +require 'set_profile_region_from_city_state'
  28 +require 'authenticated_system'
  29 +require 'needs_profile'
  30 +require 'white_list_filter'
  31 +
config/initializers/dependencies.rb
@@ -1,28 +0,0 @@ @@ -1,28 +0,0 @@
1 -require 'pp'  
2 -  
3 -# third-party libraries  
4 -require 'will_paginate'  
5 -require 'will_paginate/array'  
6 -require 'nokogiri'  
7 -  
8 -# dependencies at vendor, firstly loaded on Gemfile  
9 -vendor = Dir.glob('vendor/{,plugins/}*') - ['vendor/plugins']  
10 -vendor.each do |dir|  
11 - init_rb = "#{Rails.root}/#{dir}/init.rb"  
12 - require init_rb if File.file? init_rb  
13 -end  
14 -  
15 -# locally-developed modules  
16 -require 'acts_as_filesystem'  
17 -require 'acts_as_having_settings'  
18 -require 'acts_as_having_boxes'  
19 -require 'acts_as_having_image'  
20 -require 'acts_as_having_posts'  
21 -require 'acts_as_customizable'  
22 -require 'route_if'  
23 -require 'maybe_add_http'  
24 -require 'set_profile_region_from_city_state'  
25 -require 'authenticated_system'  
26 -require 'needs_profile'  
27 -require 'white_list_filter'  
28 -  
config/initializers/plugins.rb
@@ -5,3 +5,4 @@ require &#39;noosfero/plugin/mailer_base&#39; @@ -5,3 +5,4 @@ require &#39;noosfero/plugin/mailer_base&#39;
5 require 'noosfero/plugin/settings' 5 require 'noosfero/plugin/settings'
6 require 'noosfero/plugin/spammable' 6 require 'noosfero/plugin/spammable'
7 Noosfero::Plugin.initialize! 7 Noosfero::Plugin.initialize!
  8 +
lib/noosfero.rb
1 -# encoding: utf-8 1 +require_relative 'noosfero/version'
  2 +require_relative 'noosfero/constants'
2 3
3 module Noosfero 4 module Noosfero
4 5
@@ -106,6 +107,3 @@ module Noosfero @@ -106,6 +107,3 @@ module Noosfero
106 107
107 end 108 end
108 109
109 -require 'noosfero/version'  
110 -require 'noosfero/constants'  
111 -require 'noosfero/core_ext'  
lib/noosfero/multi_tenancy.rb
@@ -17,6 +17,7 @@ module Noosfero @@ -17,6 +17,7 @@ module Noosfero
17 end 17 end
18 18
19 def self.setup!(host) 19 def self.setup!(host)
  20 + return unless Noosfero::MultiTenancy.on?
20 Noosfero::MultiTenancy.db_by_host = host 21 Noosfero::MultiTenancy.db_by_host = host
21 end 22 end
22 23