2
0
mirror of https://github.com/moebooru/moebooru synced 2025-09-01 06:25:13 +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 class Post < ActiveRecord::Base
STATUSES = %w(active pending flagged deleted) STATUSES = %w(active pending flagged deleted)
@@ -45,21 +43,21 @@ class Post < ActiveRecord::Base
Post.available.where('posts.id < ?', id).maximum(:id) Post.available.where('posts.id < ?', id).maximum(:id)
end end
include PostSqlMethods include Post::SqlMethods
include PostCommentMethods include Post::CommentMethods
include PostImageStoreMethods include Post::ImageStoreMethods
include PostVoteMethods include Post::VoteMethods
include PostTagMethods include Post::TagMethods
include PostCountMethods include Post::CountMethods
include PostCacheMethods include Post::CacheMethods
include PostParentMethods if CONFIG["enable_parent_posts"] include Post::ParentMethods if CONFIG["enable_parent_posts"]
include PostFileMethods include Post::FileMethods
include PostChangeSequenceMethods include Post::ChangeSequenceMethods
include PostRatingMethods include Post::RatingMethods
include PostStatusMethods include Post::StatusMethods
include PostApiMethods include Post::ApiMethods
include PostMirrorMethods include Post::MirrorMethods
include PostFrameMethods include Post::FrameMethods
def destroy_with_reason(reason, current_user) def destroy_with_reason(reason, current_user)
Post.transaction do Post.transaction do

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -4,7 +4,7 @@ require "zlib"
# These are methods dealing with getting the image and generating the thumbnail. # 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 # 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. # to be called in a specific order, they've been bundled into one module.
module PostFileMethods module Post::FileMethods
def self.included(m) def self.included(m)
m.before_validation :download_source, :on => :create m.before_validation :download_source, :on => :create
m.before_validation :ensure_tempfile_exists, :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) def self.included(m)
m.versioned :frames_pending, :default => "", :allow_reverting_to_default => true m.versioned :frames_pending, :default => "", :allow_reverting_to_default => true
end end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
module PostParentMethods module Post::ParentMethods
module ClassMethods module ClassMethods
def update_has_children(post_id) def update_has_children(post_id)
has_children = Post.exists?(["parent_id = ? AND status <> 'deleted'", 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 attr_accessor :old_rating
def self.included(m) def self.included(m)

View File

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

View File

@@ -1,4 +1,4 @@
module PostStatusMethods module Post::StatusMethods
def status=(s) def status=(s)
return if s == status return if s == status
write_attribute(:status, s) 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 attr_accessor :tags, :new_tags, :old_tags, :old_cached_tags
module ClassMethods module ClassMethods

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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