Skip to content

Commit

Permalink
End the require mess
Browse files Browse the repository at this point in the history
* Rename and reorganize post fetcher to fix autoloading, also let it use
  Faradays default connection so we get nice redirects
* Add initializer to load libs at a central place
* added lib dir to autoload_once paths to increase thread safety
* Moved lib/exceptions.rb to lib/diaspora/ to conform namespacing
  • Loading branch information
jhass committed Mar 21, 2013
1 parent 13ee612 commit 3fc3b24
Show file tree
Hide file tree
Showing 61 changed files with 115 additions and 154 deletions.
2 changes: 0 additions & 2 deletions app/controllers/admins_controller.rb
@@ -1,5 +1,3 @@
require Rails.root.join('lib', 'statistics')

class AdminsController < ApplicationController
before_filter :authenticate_user!
before_filter :redirect_unless_admin
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/invitations_controller.rb
Expand Up @@ -2,8 +2,6 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.

require Rails.root.join('lib', 'email_inviter')

class InvitationsController < ApplicationController

before_filter :authenticate_user!, :only => [:new, :create]
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/likes_controller.rb
Expand Up @@ -2,8 +2,6 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.

require Rails.root.join("app", "presenters", "post_presenter")

class LikesController < ApplicationController
include ApplicationHelper
before_filter :authenticate_user!
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/people_controller.rb
Expand Up @@ -2,8 +2,6 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.

require Rails.root.join("lib", 'stream', "person")

class PeopleController < ApplicationController
before_filter :authenticate_user!, :except => [:show, :last_post]
before_filter :redirect_if_tag_search, :only => [:index]
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/posts_controller.rb
Expand Up @@ -2,8 +2,6 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.

require Rails.root.join("app", "presenters", "post_presenter")

class PostsController < ApplicationController
include PostsHelper

Expand Down
4 changes: 0 additions & 4 deletions app/controllers/publics_controller.rb
Expand Up @@ -2,11 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.

require Rails.root.join('lib', 'stream', 'public')
class PublicsController < ApplicationController
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

skip_before_filter :set_header_data
Expand Down
9 changes: 0 additions & 9 deletions app/controllers/streams_controller.rb
Expand Up @@ -2,15 +2,6 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.

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
before_filter :authenticate_user!
before_filter :save_selected_aspects, :only => :aspects
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/tags_controller.rb
@@ -1,8 +1,6 @@
# 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 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
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/users_controller.rb
Expand Up @@ -3,9 +3,6 @@
# the COPYRIGHT file.

class UsersController < ApplicationController
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]

respond_to :html
Expand Down
3 changes: 0 additions & 3 deletions app/helpers/markdownify_helper.rb
Expand Up @@ -2,9 +2,6 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.

require Rails.root.join('lib', 'diaspora', 'markdownify')
require 'redcarpet/render_strip'

module MarkdownifyHelper
def markdownify(target, render_options={})

Expand Down
2 changes: 1 addition & 1 deletion app/models/jobs/http_multi.rb
Expand Up @@ -17,7 +17,7 @@ def self.perform(user_id, encoded_object_xml, person_ids, dispatcher_class_as_st
people = Person.where(:id => person_ids)

dispatcher = dispatcher_class_as_string.constantize
hydra = HydraWrapper.new(user, people, encoded_object_xml, dispatcher)
hydra = ::HydraWrapper.new(user, people, encoded_object_xml, dispatcher)

hydra.enqueue_batch
hydra.run
Expand Down
3 changes: 0 additions & 3 deletions app/models/person.rb
Expand Up @@ -2,9 +2,6 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.

require 'uri'
require Rails.root.join('lib', 'hcard')

class Person < ActiveRecord::Base
include ROXML
include Encryptor::Public
Expand Down
2 changes: 0 additions & 2 deletions app/models/photo.rb
Expand Up @@ -3,8 +3,6 @@
# the COPYRIGHT file.

class Photo < ActiveRecord::Base
require 'carrierwave/orm/activerecord'

include Diaspora::Federated::Shareable
include Diaspora::Commentable
include Diaspora::Shareable
Expand Down
5 changes: 2 additions & 3 deletions app/models/service.rb
Expand Up @@ -4,7 +4,6 @@

class Service < ActiveRecord::Base
include ActionView::Helpers::TextHelper
require Rails.root.join('app', 'helpers', 'markdownify_helper')
include MarkdownifyHelper

belongs_to :user
Expand Down Expand Up @@ -39,5 +38,5 @@ def profile_photo_url
end

end
require Rails.root.join('app', 'models', 'services', 'facebook')
require Rails.root.join('app', 'models', 'services', 'twitter')
require 'services/facebook'
require 'services/twitter'
2 changes: 0 additions & 2 deletions app/models/services/facebook.rb
@@ -1,7 +1,5 @@
require 'uri'
class Services::Facebook < Service
include Rails.application.routes.url_helpers
require Rails.root.join('app', 'helpers', 'markdownify_helper')
include MarkdownifyHelper

OVERRIDE_FIELDS_ON_FB_UPDATE = [:contact_id, :person_id, :request_id, :invitation_id, :photo_url, :name, :username]
Expand Down
2 changes: 0 additions & 2 deletions app/models/services/twitter.rb
@@ -1,5 +1,3 @@
require 'uri'

class Services::Twitter < Service
MAX_CHARACTERS = 140
SHORTENED_URL_LENGTH = 21
Expand Down
1 change: 0 additions & 1 deletion app/models/status_message.rb
Expand Up @@ -159,7 +159,6 @@ def queue_gather_oembed_data
end

def contains_oembed_url_in_text?
require 'uri'
urls = URI.extract(self.raw_message, ['http', 'https'])
self.oembed_url = urls.find{ |url| !TRUSTED_OEMBED_PROVIDERS.find(url).nil? }
end
Expand Down
3 changes: 0 additions & 3 deletions app/models/user.rb
Expand Up @@ -2,9 +2,6 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.

require Rails.root.join('lib', 'salmon', 'salmon')
require Rails.root.join('lib', 'postzord', 'dispatcher')

class User < ActiveRecord::Base
include Encryptor::Private
include Connecting
Expand Down
3 changes: 0 additions & 3 deletions app/models/user/querying.rb
Expand Up @@ -2,9 +2,6 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.

require Rails.root.join('lib', 'evil_query')


#TODO: THIS FILE SHOULD NOT EXIST, EVIL SQL SHOULD BE ENCAPSULATED IN EvilQueries,
#throwing all of this stuff in user violates demeter like WHOA
module User::Querying
Expand Down
1 change: 0 additions & 1 deletion app/presenters/o_embed_presenter.rb
@@ -1,4 +1,3 @@
require 'uri'
class OEmbedPresenter
include PostsHelper
include ActionView::Helpers::TextHelper
Expand Down
2 changes: 0 additions & 2 deletions app/presenters/post_presenter.rb
@@ -1,5 +1,3 @@
require Rails.root.join('lib', 'template_picker')

class PostPresenter
attr_accessor :post, :current_user

Expand Down
4 changes: 2 additions & 2 deletions config/application.rb
Expand Up @@ -32,8 +32,8 @@ class Application < Rails::Application
# -- all .rb files in that directory are automatically loaded.

# Add additional load paths for your own custom dirs
config.autoload_paths += %W(#{config.root}/app/presenters)
config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += %W{#{config.root}/app/presenters}
config.autoload_once_paths += %W{#{config.root}/lib}

# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named
Expand Down
2 changes: 0 additions & 2 deletions config/environment.rb
Expand Up @@ -13,7 +13,6 @@ def sqlite?

# Load the rails application
require Pathname.new(__FILE__).dirname.expand_path.join('application')
require Rails.root.join("lib", "exceptions")

# Load configuration system early
require Rails.root.join('config', 'load_config')
Expand All @@ -27,7 +26,6 @@ def sqlite?

# Initialize the rails application
Diaspora::Application.initialize!
require Rails.root.join('lib', 'federation_logger')

# allow token auth only for posting activitystream photos
module Devise
Expand Down
3 changes: 1 addition & 2 deletions config/initializers/acts_as_taggable_on.rb
@@ -1,3 +1,2 @@

ActsAsTaggableOn.force_lowercase = true

require Rails.root.join("app", "models", "acts_as_taggable_on", "tag")
36 changes: 36 additions & 0 deletions config/initializers/load_libraries.rb
@@ -0,0 +1,36 @@
# Stdlib
require 'cgi'
require 'uri'

# Not auto required gems
require 'active_support/base64'
require 'builder/xchar'
require 'carrierwave/orm/activerecord'
require 'erb'
require 'redcarpet/render_strip'
require 'typhoeus'

# Presenters
require 'post_presenter'

# Helpers
require 'markdownify_helper'

# Our libs
require 'collect_user_photos'
require 'diaspora'
require 'email_inviter'
require 'evil_query'
require 'federation_logger'
require 'h_card'
require 'hydra_wrapper'
require 'postzord'
require 'publisher'
require 'pubsubhubbub'
require 'salmon'
require 'statistics'
require 'stream'
require 'template_picker'
require 'webfinger'
require 'webfinger_profile'

2 changes: 1 addition & 1 deletion features/step_definitions/debug_steps.rb
@@ -1,6 +1,6 @@
module DebuggingCukeHelpers
def start_debugging
require 'ruby-debug'
require 'debug'
debugger
true
end
Expand Down
2 changes: 0 additions & 2 deletions features/step_definitions/web_steps.rb
Expand Up @@ -4,8 +4,6 @@
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.

require 'uri'
require 'cgi'
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))

module WithinHelpers
Expand Down
6 changes: 5 additions & 1 deletion lib/diaspora.rb
Expand Up @@ -3,5 +3,9 @@
# the COPYRIGHT file.

module Diaspora
autoload :Parser
require 'diaspora/exceptions'
require 'diaspora/parser'
require 'diaspora/fetcher'
require 'diaspora/markdownify'
require 'diaspora/exporter'
end
File renamed without changes.
2 changes: 0 additions & 2 deletions lib/diaspora/federated/base.rb
Expand Up @@ -9,8 +9,6 @@

#including this module lets you federate an object at the most basic of level

require 'builder/xchar'

module Diaspora
module Federated
module Base
Expand Down
5 changes: 5 additions & 0 deletions lib/diaspora/fetcher.rb
@@ -0,0 +1,5 @@
module Diaspora
module Fetcher
require 'diaspora/fetcher/public'
end
end

0 comments on commit 3fc3b24

Please sign in to comment.