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:
@@ -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
|
||||
|
@@ -1,4 +1,4 @@
|
||||
module PostApiMethods
|
||||
module Post::ApiMethods
|
||||
attr_accessor :similarity
|
||||
|
||||
def api_attributes
|
||||
|
@@ -1,4 +1,4 @@
|
||||
module PostCacheMethods
|
||||
module Post::CacheMethods
|
||||
def self.included(m)
|
||||
m.after_save :expire_cache
|
||||
m.after_destroy :expire_cache
|
||||
|
@@ -1,4 +1,4 @@
|
||||
module PostChangeSequenceMethods
|
||||
module Post::ChangeSequenceMethods
|
||||
attr_accessor :increment_change_seq
|
||||
|
||||
def self.included(m)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
module PostCommentMethods
|
||||
module Post::CommentMethods
|
||||
def self.included(m)
|
||||
m.has_many :comments, lambda { order "id" }
|
||||
end
|
||||
|
@@ -1,4 +1,4 @@
|
||||
module PostCountMethods
|
||||
module Post::CountMethods
|
||||
module ClassMethods
|
||||
def fast_count(tags = nil)
|
||||
# A small sanitation
|
||||
|
@@ -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
|
||||
|
@@ -1,4 +1,4 @@
|
||||
module PostFrameMethods
|
||||
module Post::FrameMethods
|
||||
def self.included(m)
|
||||
m.versioned :frames_pending, :default => "", :allow_reverting_to_default => true
|
||||
end
|
||||
|
@@ -1,4 +1,4 @@
|
||||
module PostImageStoreMethods
|
||||
module Post::ImageStore
|
||||
module AmazonS3
|
||||
def move_file
|
||||
begin
|
||||
|
@@ -1,4 +1,4 @@
|
||||
module PostImageStoreMethods
|
||||
module Post::ImageStore
|
||||
module LocalFlat
|
||||
def file_path
|
||||
"#{Rails.root}/public/data/#{file_name}"
|
||||
|
@@ -1,4 +1,4 @@
|
||||
module PostImageStoreMethods
|
||||
module Post::ImageStore
|
||||
module LocalFlatWithAmazonS3Backup
|
||||
def move_file
|
||||
FileUtils.mv(tempfile_path, file_path)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
module PostImageStoreMethods
|
||||
module Post::ImageStore
|
||||
module LocalHierarchy
|
||||
def file_hierarchy
|
||||
"%s/%s" % [md5[0,2], md5[2,2]]
|
||||
|
@@ -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]]
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
|
@@ -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])
|
||||
|
@@ -1,4 +1,4 @@
|
||||
module PostRatingMethods
|
||||
module Post::RatingMethods
|
||||
attr_accessor :old_rating
|
||||
|
||||
def self.included(m)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
module PostSqlMethods
|
||||
module Post::SqlMethods
|
||||
module ClassMethods
|
||||
def find_by_tag_join(tag, options = {})
|
||||
tag = tag.downcase.tr(" ", "_")
|
||||
|
@@ -1,4 +1,4 @@
|
||||
module PostStatusMethods
|
||||
module Post::StatusMethods
|
||||
def status=(s)
|
||||
return if s == status
|
||||
write_attribute(:status, s)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
module PostTagMethods
|
||||
module Post::TagMethods
|
||||
attr_accessor :tags, :new_tags, :old_tags, :old_cached_tags
|
||||
|
||||
module ClassMethods
|
||||
|
@@ -1,4 +1,4 @@
|
||||
module PostVoteMethods
|
||||
module Post::VoteMethods
|
||||
module ClassMethods
|
||||
def recalculate_score(id=nil)
|
||||
conds = []
|
||||
|
@@ -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'
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
module TagApiMethods
|
||||
module Tag::ApiMethods
|
||||
def self.included(m)
|
||||
m.extend(ClassMethods)
|
||||
end
|
||||
|
@@ -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
|
||||
|
@@ -1,4 +1,4 @@
|
||||
module TagParseMethods
|
||||
module Tag::ParseMethods
|
||||
module ClassMethods
|
||||
def scan_query(query)
|
||||
query.to_s.to_valid_utf8.downcase.split.uniq
|
||||
|
@@ -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.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
module TagTypeMethods
|
||||
module Tag::TypeMethods
|
||||
module ClassMethods
|
||||
attr_accessor :type_map
|
||||
|
||||
|
Reference in New Issue
Block a user