2
0
mirror of https://github.com/moebooru/moebooru synced 2025-08-31 05:55:11 +00:00

Replace explicit require with autoloader.

This commit is contained in:
edogawaconan
2014-08-23 09:45:32 +09:00
parent b334e45a6b
commit 697bbea8a2
27 changed files with 56 additions and 56 deletions

View File

@@ -1,5 +1,3 @@
Dir["#{Rails.root}/app/models/post/**/*.rb"].each {|x| require_dependency x}
class Post < ActiveRecord::Base
STATUSES = %w(active pending flagged deleted)
@@ -45,21 +43,21 @@ class Post < ActiveRecord::Base
Post.available.where('posts.id < ?', id).maximum(:id)
end
include PostSqlMethods
include PostCommentMethods
include PostImageStoreMethods
include PostVoteMethods
include PostTagMethods
include PostCountMethods
include PostCacheMethods
include PostParentMethods if CONFIG["enable_parent_posts"]
include PostFileMethods
include PostChangeSequenceMethods
include PostRatingMethods
include PostStatusMethods
include PostApiMethods
include PostMirrorMethods
include PostFrameMethods
include Post::SqlMethods
include Post::CommentMethods
include Post::ImageStoreMethods
include Post::VoteMethods
include Post::TagMethods
include Post::CountMethods
include Post::CacheMethods
include Post::ParentMethods if CONFIG["enable_parent_posts"]
include Post::FileMethods
include Post::ChangeSequenceMethods
include Post::RatingMethods
include Post::StatusMethods
include Post::ApiMethods
include Post::MirrorMethods
include Post::FrameMethods
def destroy_with_reason(reason, current_user)
Post.transaction do

View File

@@ -1,4 +1,4 @@
module PostApiMethods
module Post::ApiMethods
attr_accessor :similarity
def api_attributes

View File

@@ -1,4 +1,4 @@
module PostCacheMethods
module Post::CacheMethods
def self.included(m)
m.after_save :expire_cache
m.after_destroy :expire_cache

View File

@@ -1,4 +1,4 @@
module PostChangeSequenceMethods
module Post::ChangeSequenceMethods
attr_accessor :increment_change_seq
def self.included(m)

View File

@@ -1,4 +1,4 @@
module PostCommentMethods
module Post::CommentMethods
def self.included(m)
m.has_many :comments, lambda { order "id" }
end

View File

@@ -1,4 +1,4 @@
module PostCountMethods
module Post::CountMethods
module ClassMethods
def fast_count(tags = nil)
# A small sanitation

View File

@@ -4,7 +4,7 @@ require "zlib"
# These are methods dealing with getting the image and generating the thumbnail.
# It works in conjunction with the image_store methods. Since these methods have
# to be called in a specific order, they've been bundled into one module.
module PostFileMethods
module Post::FileMethods
def self.included(m)
m.before_validation :download_source, :on => :create
m.before_validation :ensure_tempfile_exists, :on => :create

View File

@@ -1,4 +1,4 @@
module PostFrameMethods
module Post::FrameMethods
def self.included(m)
m.versioned :frames_pending, :default => "", :allow_reverting_to_default => true
end

View File

@@ -1,4 +1,4 @@
module PostImageStoreMethods
module Post::ImageStore
module AmazonS3
def move_file
begin

View File

@@ -1,4 +1,4 @@
module PostImageStoreMethods
module Post::ImageStore
module LocalFlat
def file_path
"#{Rails.root}/public/data/#{file_name}"

View File

@@ -1,4 +1,4 @@
module PostImageStoreMethods
module Post::ImageStore
module LocalFlatWithAmazonS3Backup
def move_file
FileUtils.mv(tempfile_path, file_path)

View File

@@ -1,4 +1,4 @@
module PostImageStoreMethods
module Post::ImageStore
module LocalHierarchy
def file_hierarchy
"%s/%s" % [md5[0,2], md5[2,2]]

View File

@@ -1,8 +1,6 @@
require "mirror"
require "erb"
include ERB::Util
module PostImageStoreMethods
module Post::ImageStore
module RemoteHierarchy
def file_hierarchy
"%s/%s" % [md5[0,2], md5[2,2]]

View File

@@ -1,20 +1,26 @@
module PostImageStoreMethods
module Post::ImageStoreMethods
def self.included(m)
case CONFIG["image_store"]
when :local_flat
m.__send__(:include, PostImageStoreMethods::LocalFlat)
m.__send__(:include, Post::ImageStore::LocalFlat)
when :local_flat_with_amazon_s3_backup
m.__send__(:include, PostImageStoreMethods::LocalFlatWithAmazonS3Backup)
m.__send__(:include, Post::ImageStore::LocalFlatWithAmazonS3Backup)
when :local_hierarchy
m.__send__(:include, PostImageStoreMethods::LocalHierarchy)
m.__send__(:include, Post::ImageStore::LocalHierarchy)
when :remote_hierarchy
m.__send__(:include, PostImageStoreMethods::RemoteHierarchy)
m.__send__(:include, Post::ImageStore::RemoteHierarchy)
when :amazon_s3
m.__send__(:include, PostImageStoreMethods::AmazonS3)
m.__send__(:include, Post::ImageStore::AmazonS3)
end
end
private
def url_encode(*args)
ERB::Util.url_encode *args
end
end

View File

@@ -2,7 +2,7 @@ require "mirror"
class MirrorError < Exception ; end
module PostMirrorMethods
module Post::MirrorMethods
# On :normal, upload all files to all mirrors except :previews_only ones.
# On :previews_only, upload previews to previews_only mirrors.
def upload_to_mirrors_internal(mode=:normal)

View File

@@ -1,4 +1,4 @@
module PostParentMethods
module Post::ParentMethods
module ClassMethods
def update_has_children(post_id)
has_children = Post.exists?(["parent_id = ? AND status <> 'deleted'", post_id])

View File

@@ -1,4 +1,4 @@
module PostRatingMethods
module Post::RatingMethods
attr_accessor :old_rating
def self.included(m)

View File

@@ -1,4 +1,4 @@
module PostSqlMethods
module Post::SqlMethods
module ClassMethods
def find_by_tag_join(tag, options = {})
tag = tag.downcase.tr(" ", "_")

View File

@@ -1,4 +1,4 @@
module PostStatusMethods
module Post::StatusMethods
def status=(s)
return if s == status
write_attribute(:status, s)

View File

@@ -1,4 +1,4 @@
module PostTagMethods
module Post::TagMethods
attr_accessor :tags, :new_tags, :old_tags, :old_cached_tags
module ClassMethods

View File

@@ -1,4 +1,4 @@
module PostVoteMethods
module Post::VoteMethods
module ClassMethods
def recalculate_score(id=nil)
conds = []

View File

@@ -1,11 +1,9 @@
Dir["#{Rails.root}/app/models/tag/**/*.rb"].each {|x| require_dependency x}
class Tag < ActiveRecord::Base
include TagTypeMethods
include TagCacheMethods
include TagRelatedTagMethods
include TagParseMethods
include TagApiMethods
include Tag::TypeMethods
include Tag::CacheMethods
include Tag::RelatedTagMethods
include Tag::ParseMethods
include Tag::ApiMethods
has_and_belongs_to_many :_posts, :class_name => 'Post'
has_many :tag_aliases, :foreign_key => 'alias_id'

View File

@@ -1,4 +1,4 @@
module TagApiMethods
module Tag::ApiMethods
def self.included(m)
m.extend(ClassMethods)
end

View File

@@ -1,4 +1,4 @@
module TagCacheMethods
module Tag::CacheMethods
def self.included(m)
m.after_save :update_cache
m.after_create :update_cache_on_create

View File

@@ -1,4 +1,4 @@
module TagParseMethods
module Tag::ParseMethods
module ClassMethods
def scan_query(query)
query.to_s.to_valid_utf8.downcase.split.uniq

View File

@@ -1,4 +1,4 @@
module TagRelatedTagMethods
module Tag::RelatedTagMethods
module ClassMethods
# Returns tags (with type specified by input) related by input tag
# In array of hashes.

View File

@@ -1,4 +1,4 @@
module TagTypeMethods
module Tag::TypeMethods
module ClassMethods
attr_accessor :type_map