Commit a8de3a5a authored by Steven Hancock's avatar Steven Hancock

Rails.root and File.join cleanup

- `Rails.root` is a `Pathname`, so let's use `Rails.root.join`
- Clean up most of the remaining `File.join`s
parent e021fd82
require File.join(Rails.root, 'lib','statistics')
require Rails.root.join('lib', 'statistics')
class AdminsController < ApplicationController
before_filter :authenticate_user!
......
......@@ -91,7 +91,7 @@ class AspectsController < ApplicationController
@contacts = @contacts_in_aspect + @contacts_not_in_aspect
unless @aspect
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
render :file => Rails.root.join('public', '404.html').to_s, :layout => false, :status => 404
else
@aspect_ids = [@aspect.id]
@aspect_contacts_count = @aspect.contacts.size
......
......@@ -13,7 +13,7 @@ class HomeController < ApplicationController
redirect_to stream_path
end
elsif is_mobile_device?
unless(File.exist?("#{Rails.root}/app/views/home/_show.mobile.erb"))
unless(File.exist?(Rails.root.join('app', 'views', 'home', '_show.mobile.erb')))
redirect_to user_session_path
else
render :show, :layout => 'post'
......
......@@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require File.join(Rails.root, "lib", 'stream', "person")
require Rails.root.join("lib", 'stream', "person")
class PeopleController < ApplicationController
before_filter :authenticate_user!, :except => [:show, :last_post]
......@@ -13,7 +13,7 @@ class PeopleController < ApplicationController
respond_to :js, :only => [:tag_index]
rescue_from ActiveRecord::RecordNotFound do
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
render :file => Rails.root.join('public', '404.html').to_s, :layout => false, :status => 404
end
helper_method :search_query
......
......@@ -2,11 +2,11 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require File.join(Rails.root, 'lib', 'stream', 'public')
require Rails.root.join('lib', 'stream', 'public')
class PublicsController < ApplicationController
require File.join(Rails.root, '/lib/diaspora/parser')
require File.join(Rails.root, '/lib/postzord/receiver/public')
require File.join(Rails.root, '/lib/postzord/receiver/private')
require Rails.root.join('lib', 'diaspora', 'parser')
require Rails.root.join('lib', 'postzord', 'receiver', 'public')
require Rails.root.join('lib', 'postzord', 'receiver', 'private')
include Diaspora::Parser
# We use newrelic_ignore to prevent artifical RPM bloat; however,
......
......@@ -2,13 +2,13 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require File.join(Rails.root, "lib", "stream", "aspect")
require File.join(Rails.root, "lib", "stream", "multi")
require File.join(Rails.root, "lib", "stream", "comments")
require File.join(Rails.root, "lib", "stream", "likes")
require File.join(Rails.root, "lib", "stream", "mention")
require File.join(Rails.root, "lib", "stream", "followed_tag")
require File.join(Rails.root, "lib", "stream", "activity")
require Rails.root.join("lib", "stream", "aspect")
require Rails.root.join("lib", "stream", "multi")
require Rails.root.join("lib", "stream", "comments")
require Rails.root.join("lib", "stream", "likes")
require Rails.root.join("lib", "stream", "mention")
require Rails.root.join("lib", "stream", "followed_tag")
require Rails.root.join("lib", "stream", "activity")
class StreamsController < ApplicationController
......
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require File.join(Rails.root, 'app', 'models', 'acts_as_taggable_on', 'tag')
require File.join(Rails.root, 'lib', 'stream', 'tag')
require Rails.root.join('app', 'models', 'acts_as_taggable_on', 'tag')
require Rails.root.join('lib', 'stream', 'tag')
class TagsController < ApplicationController
skip_before_filter :set_grammatical_gender
......
......@@ -3,8 +3,8 @@
# the COPYRIGHT file.
class UsersController < ApplicationController
require File.join(Rails.root, 'lib/diaspora/exporter')
require File.join(Rails.root, 'lib/collect_user_photos')
require Rails.root.join('lib', 'diaspora', 'exporter')
require Rails.root.join('lib', 'collect_user_photos')
before_filter :authenticate_user!, :except => [:new, :create, :public, :user_photo]
......
......@@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require File.expand_path("#{Rails.root}/lib/diaspora/markdownify")
require Rails.root.join('lib', 'diaspora', 'markdownify')
module MarkdownifyHelper
def markdownify(target, render_options={})
......
......@@ -3,7 +3,7 @@
# the COPYRIGHT file.
require 'uri'
require File.join(Rails.root, 'lib', 'enviroment_configuration')
require Rails.root.join('lib', 'enviroment_configuration')
class AppConfig < Settingslogic
def self.source_file_name
......@@ -11,9 +11,9 @@ class AppConfig < Settingslogic
puts "using remote application.yml"
return ENV['application_yml']
end
config_file = File.join(Rails.root, "config", "application.yml")
config_file = Rails.root.join("config", "application.yml")
if !File.exists?(config_file) && (Rails.env == 'test' || Rails.env.include?("integration") || EnviromentConfiguration.heroku?)
config_file = File.join(Rails.root, "config", "application.yml.example")
config_file = Rails.root.join("config", "application.yml.example")
end
config_file
end
......@@ -96,7 +96,7 @@ HELP
end
def self.have_old_config_file?
File.exists?(File.join(Rails.root, "config", "app.yml")) || (File.exists?(File.join(Rails.root, "config", "app_config.yml")))
File.exists?(Rails.root.join("config", "app.yml")) || (File.exists?(Rails.root.join("config", "app_config.yml")))
end
def self.new_relic_app_name
......
......@@ -4,7 +4,7 @@
module Jobs
class Base
Dir["#{Rails.root}/app/models/jobs/mail/*.rb"].each {|file| require file }
Dir[Rails.root.join('app', 'models', 'jobs', 'mail', '*.rb')].each {|file| require file }
#TODO these should be subclassed real exceptions
DUMB_ERROR_MESSAGES = [
......
......@@ -3,7 +3,7 @@
# the COPYRIGHT file.
require 'uri'
require File.join(Rails.root, 'lib/hydra_wrapper')
require Rails.root.join('lib', 'hydra_wrapper')
module Jobs
class HttpMulti < Base
......
......@@ -6,7 +6,7 @@ module Jobs
class NotifyLocalUsers < Base
@queue = :receive_local
require File.join(Rails.root, 'app/models/notification')
require Rails.root.join('app', 'models', 'notification')
def self.perform(user_ids, object_klass, object_id, person_id)
......
......@@ -7,7 +7,7 @@ module Jobs
@queue = :http_service
def self.perform(sender_public_url)
require File.join(Rails.root, 'lib/pubsubhubbub')
require Rails.root.join('lib', 'pubsubhubbub')
atom_url = sender_public_url + '.atom'
Pubsubhubbub.new(AppConfig[:pubsub_server]).publish(atom_url)
end
......
......@@ -3,7 +3,7 @@
# the COPYRIGHT file.
require File.join(Rails.root, 'lib/postzord/receiver/private')
require Rails.root.join('lib', 'postzord', 'receiver', 'private')
module Jobs
class ReceiveEncryptedSalmon < Base
@queue = :receive_salmon
......
......@@ -2,8 +2,8 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require File.join(Rails.root, 'lib/postzord/receiver/private')
require File.join(Rails.root, 'lib/postzord/receiver/local_batch')
require Rails.root.join('lib', 'postzord', 'receiver', 'private')
require Rails.root.join('lib', 'postzord', 'receiver', 'local_batch')
module Jobs
class ReceiveLocalBatch < Base
......
......@@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require File.join(Rails.root, 'lib/postzord/receiver/public')
require Rails.root.join('lib', 'postzord', 'receiver', 'public')
module Jobs
class ReceiveUnencryptedSalmon < Base
......
......@@ -3,7 +3,7 @@
# the COPYRIGHT file.
require 'uri'
require File.join(Rails.root, 'lib/hcard')
require Rails.root.join('lib', 'hcard')
class Person < ActiveRecord::Base
include ROXML
......
......@@ -27,5 +27,5 @@ class Service < ActiveRecord::Base
end
end
require File.join(Rails.root, 'app/models/services/facebook')
require File.join(Rails.root, 'app/models/services/twitter')
require Rails.root.join('app', 'models', 'services', 'facebook')
require Rails.root.join('app', 'models', 'services', 'twitter')
......@@ -2,8 +2,8 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require File.join(Rails.root, 'lib/salmon/salmon')
require File.join(Rails.root, 'lib/postzord/dispatcher')
require Rails.root.join('lib', 'salmon', 'salmon')
require Rails.root.join('lib', 'postzord', 'dispatcher')
class User < ActiveRecord::Base
include Encryptor::Private
......
......@@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require File.join(Rails.root, 'lib', 'evil_query')
require Rails.root.join('lib', 'evil_query')
#TODO: THIS FILE SHOULD NOT EXIST, EVIL SQL SHOULD BE ENCAPSULATED IN EvilQueries,
......
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'template_picker')
require Rails.root.join('lib', 'template_picker')
class PostPresenter
attr_accessor :post, :current_user
......
......@@ -11,4 +11,4 @@
- rescue
:erb
<%= File.open(File.join(Rails.root, 'public/default.html')).read %>
<%= File.open(Rails.root.join('public', 'default.html')).read %>
......@@ -24,7 +24,7 @@ USERNAME_BLACKLIST = ['admin', 'administrator', 'hostmaster', 'info', 'postmaste
# Initialize the rails application
Diaspora::Application.initialize!
require File.join(Rails.root, 'lib', 'federation_logger')
require Rails.root.join('lib', 'federation_logger')
# allow token auth only for posting activitystream photos
module Devise
......
......@@ -2,4 +2,4 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require File.join(Rails.root, 'app', 'models', 'app_config')
\ No newline at end of file
require Rails.root.join('app', 'models', 'app_config')
\ No newline at end of file
......@@ -6,7 +6,7 @@ def load_config_yaml filename
YAML.load(ERB.new(File.read(filename)).result)
end
oauth_keys_file = "#{Rails.root}/config/oauth_keys.yml"
oauth_keys_file = Rails.root.join('config', 'oauth_keys.yml').to_s
SERVICES = load_config_yaml("#{oauth_keys_file}.example")
......
......@@ -7,7 +7,7 @@ ENV["SSL_CERT_FILE"] = AppConfig[:ca_file]
CarrierWave.configure do |config|
if !Rails.env.test? && AppConfig[:s3_key] && AppConfig[:s3_secret] && AppConfig[:s3_bucket] && AppConfig[:s3_region]
config.storage = :fog
config.cache_dir = "#{Rails.root}/tmp/uploads"
config.cache_dir = Rails.root.join('tmp', 'uploads').to_s
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => AppConfig[:s3_key],
......
......@@ -2,4 +2,4 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require File.join(Rails.root, 'lib/direction_detector')
require Rails.root.join('lib', 'direction_detector')
Dir["#{Rails.root}/app/models/jobs/mail/*.rb"].each { |file| require file }
\ No newline at end of file
Dir[Rails.root.join('app', 'models', 'jobs', 'mail', '*.rb')].each { |file| require file }
\ No newline at end of file
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require File.join(Rails.root, 'lib/messagebus/mailer')
require Rails.root.join('lib', 'messagebus', 'mailer')
Diaspora::Application.configure do
config.action_mailer.default_url_options = {:protocol => AppConfig[:pod_uri].scheme,
......
......@@ -36,6 +36,6 @@ end
if AppConfig[:mount_resque_web]
require 'resque/server'
require File.join(Rails.root, 'lib/admin_rack')
require Rails.root.join('lib', 'admin_rack')
Resque::Server.use AdminRack
end
class UndoAddingIndicies < ActiveRecord::Migration
require File.join(Rails.root, 'db/migrate/20110213052742_add_more_indicies')
require Rails.root.join('db', 'migrate', '20110213052742_add_more_indicies')
def self.up
AddMoreIndicies.down
end
......
require File.join(Rails.root, 'db/migrate/20110105051803_create_import_tables')
require Rails.root.join('db', 'migrate', '20110105051803_create_import_tables')
class DropImportTables < ActiveRecord::Migration
def self.up
CreateImportTables.down
......
require File.join(Rails.root, 'db/migrate/20110319005509_add_processed_to_post')
require Rails.root.join('db', 'migrate', '20110319005509_add_processed_to_post')
class UnprocessedImageUploader < ActiveRecord::Migration
def self.up
AddProcessedToPost.down
......
class DropAspectsOpen < ActiveRecord::Migration
require File.join(Rails.root, "db", "migrate", "20110202015222_add_open_to_aspects")
require Rails.root.join("db", "migrate", "20110202015222_add_open_to_aspects")
def self.up
AddOpenToAspects.down
end
......
......@@ -14,7 +14,7 @@ class ShareVisibility < ActiveRecord::Base
belongs_to :contact
end
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'share_visibility_converter')
require Rails.root.join('lib', 'share_visibility_converter')
class MoveRecentlyHiddenPostsToUser < ActiveRecord::Migration
def self.up
......
......@@ -10,9 +10,9 @@
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Mayor.create(:name => 'Daley', :city => citie
require File.join(File.dirname(__FILE__), "..", "config", "environment")
require Rails.root.join('config', 'environment')
require 'factory_girl_rails'
require File.join(File.dirname(__FILE__), "..", "spec", "helper_methods")
require Rails.root.join('spec', 'helper_methods')
include HelperMethods
alice = Factory(:user_with_aspect, :username => "alice", :password => 'evankorth')
......@@ -47,8 +47,8 @@ Role.add_admin(bob.person)
puts "done!"
require File.join(File.dirname(__FILE__), '..', 'spec', 'support', 'fake_resque')
require File.join(File.dirname(__FILE__), '..', 'spec', 'support', 'user_methods')
require Rails.root.join('spec', 'support', 'fake_resque')
require Rails.root.join('spec', 'support', 'user_methods')
print "Seeding post data..."
time_interval = 1000
......
Given /^configuration parameter (\w+) is ([^ ]+)$/ do |key, value|
require Rails.root.join('config', "initializers", "_load_app_config.rb")
app_value = AppConfig[ key.to_sym]
app_value = AppConfig[key.to_sym]
assert_equal value, app_value,
"You must set #{key} to #{value} and kill running server"
end
......
......@@ -49,8 +49,8 @@ Spork.prefork do
require File.join(File.dirname(__FILE__), "integration_sessions_controller")
require File.join(File.dirname(__FILE__), "poor_mans_webmock")
require File.join(File.dirname(__FILE__), "..", "..", "spec", "helper_methods")
require File.join(File.dirname(__FILE__), "..", "..", "spec", "support","user_methods")
require Rails.root.join('spec', 'helper_methods')
require Rails.root.join('spec', 'support', 'user_methods')
include HelperMethods
# require 'webmock/cucumber'
......@@ -61,7 +61,7 @@ Spork.prefork do
AppConfig[:configured_services] << 'facebook'
end
require File.join(File.dirname(__FILE__), "..", "..", "spec", "support", "fake_resque")
require Rails.root.join('spec', 'support', 'fake_resque')
require File.join(File.dirname(__FILE__), 'run_resque_in_process')
......
......@@ -3,9 +3,9 @@ module CsvGenerator
PATH = '/tmp/'
BACKER_CSV_LOCATION = File.join('/usr/local/app/diaspora/', 'backer_list.csv')
#BACKER_CSV_LOCATION = File.join('/home/ilya/workspace/diaspora/', 'backer_list.csv')
WAITLIST_LOCATION = File.join(Rails.root, 'config', 'mailing_list.csv')
OFFSET_LOCATION = File.join(Rails.root, 'config', 'email_offset')
UNSUBSCRIBE_LOCATION = File.join(Rails.root, 'config', 'unsubscribe.csv')
WAITLIST_LOCATION = Rails.root.join('config', 'mailing_list.csv')
OFFSET_LOCATION = Rails.root.join('config', 'email_offset')
UNSUBSCRIBE_LOCATION = Rails.root.join('config', 'unsubscribe.csv')
def self.all_active_users
file = self.filename("all_active_users")
......
......@@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require File.join(Rails.root, "app", "models", "acts_as_taggable_on", "tag")
require Rails.root.join("app", "models", "acts_as_taggable_on", "tag")
module Diaspora
module Taggable
......
......@@ -9,7 +9,7 @@ module EnviromentConfiguration
end
def self.secret_token_initializer_is_not_present?
!File.exists?( File.join(Rails.root, 'config', 'initializers', 'secret_token.rb'))
!File.exists?( Rails.root.join('config', 'initializers', 'secret_token.rb'))
end
def self.prevent_fetching_community_spotlight?
......@@ -27,7 +27,7 @@ module EnviromentConfiguration
Rails.application.config.secret_token = ENV['SECRET_TOKEN']
elsif secret_token_initializer_is_not_present?
`rake generate:secret_token`
require File.join(Rails.root, 'config', 'initializers', 'secret_token.rb')
require Rails.root.join('config', 'initializers', 'secret_token.rb')
else
#do nothing
end
......
......@@ -7,7 +7,7 @@ end
if Rails.env.match(/integration/)
puts "using federation logger"
logfile = File.open(File.join(Rails.root, "/log/#{Rails.env}_federation.log"), 'a') #create log file
logfile = File.open(Rails.root.join("log", "#{Rails.env}_federation.log"), 'a') #create log file
logfile.sync = true #automatically flushes data to file
FEDERATION_LOGGER = FederationLogger.new(logfile) #constant accessible anywhere
else
......
......@@ -4,8 +4,8 @@
class Postzord::Dispatcher
require File.join(Rails.root, 'lib/postzord/dispatcher/private')
require File.join(Rails.root, 'lib/postzord/dispatcher/public')
require Rails.root.join('lib', 'postzord', 'dispatcher', 'private')
require Rails.root.join('lib', 'postzord', 'dispatcher', 'public')
attr_reader :sender, :object, :xml, :subscribers, :opts
......
......@@ -4,8 +4,8 @@
class Postzord::Receiver
require File.join(Rails.root, 'lib/postzord/receiver/private')
require File.join(Rails.root, 'lib/postzord/receiver/public')
require Rails.root.join('lib', 'postzord', 'receiver', 'private')
require Rails.root.join('lib', 'postzord', 'receiver', 'public')
def perform!
self.receive!
......
......@@ -2,8 +2,8 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require File.join(Rails.root, 'lib/webfinger')
require File.join(Rails.root, 'lib/diaspora/parser')
require Rails.root.join('lib', 'webfinger')
require Rails.root.join('lib', 'diaspora', 'parser')
class Postzord::Receiver::Private < Postzord::Receiver
......
......@@ -24,7 +24,7 @@ end
# Verify documents secured with Magic Signatures
module Salmon
autoload :Slap, File.join(Rails.root, "lib", "salmon", "slap")
autoload :EncryptedSlap, File.join(Rails.root, "lib", "salmon", "encrypted_slap")
autoload :MagicSigEnvelope, File.join(Rails.root, "lib", "salmon", "magic_sig_envelope")
autoload :Slap, Rails.root.join("lib", "salmon", "slap")
autoload :EncryptedSlap, Rails.root.join("lib", "salmon", "encrypted_slap")
autoload :MagicSigEnvelope, Rails.root.join("lib", "salmon", "magic_sig_envelope")
end
require File.join(Rails.root, "lib", "publisher")
require Rails.root.join("lib", "publisher")
class Stream::Base
TYPES_OF_POST_IN_STREAM = ['StatusMessage', 'Reshare', 'ActivityStreams::Photo']
......
......@@ -2,7 +2,7 @@ desc "revert custom landing page commit after heroku san deploys"
task :after_deploy => :environment do
# Perform this task only if custom landing page is not present in app/views/home/_show.html.haml
if (File.exist?(File.join(Rails.root, "app", "views", "home", "_show.html.erb")) || File.exist?(File.join(Rails.root, "app", "views", "home", "_show.mobile.erb"))) && system("git log | head -5 | grep 'custom\ landing\ page(s)'")
if (File.exist?(Rails.root.join("app", "views", "home", "_show.html.erb")) || File.exist?(Rails.root.join("app", "views", "home", "_show.mobile.erb"))) && system("git log | head -5 | grep 'custom\ landing\ page(s)'")
puts "-----> resetting HEAD before custom landing page commit"
system("git reset HEAD^") ? true : fail
......
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require File.join(Rails.root, 'lib', 'rake_helpers')
require Rails.root.join('lib', 'rake_helpers')
include RakeHelpers
namespace :invites do
......@@ -11,8 +11,8 @@ namespace :invites do
task :send, :number, :test do |t, args|
require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')
filename = File.join(Rails.root, 'config', 'mailing_list.csv')
offset_filename = File.join(Rails.root, 'config', 'email_offset')
filename = Rails.root.join('config', 'mailing_list.csv')
offset_filename = Rails.root.join('config', 'email_offset')
number_of_backers = args[:number] ? args[:number].to_i : 1000
offset = if File.exists?(offset_filename)
......@@ -26,7 +26,7 @@ namespace :invites do
finish_num = process_emails(filename, number_of_backers, offset, test)
new_offset = offset + finish_num + 1
File.open(File.join(Rails.root, 'config', 'email_offset'), 'w') do |f|
File.open(Rails.root.join('config', 'email_offset'), 'w') do |f|