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:
@@ -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
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
module PostApiMethods
|
module Post::ApiMethods
|
||||||
attr_accessor :similarity
|
attr_accessor :similarity
|
||||||
|
|
||||||
def api_attributes
|
def api_attributes
|
||||||
|
@@ -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
|
||||||
|
@@ -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)
|
||||||
|
@@ -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
|
||||||
|
@@ -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
|
||||||
|
@@ -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
|
||||||
|
@@ -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
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
module PostImageStoreMethods
|
module Post::ImageStore
|
||||||
module AmazonS3
|
module AmazonS3
|
||||||
def move_file
|
def move_file
|
||||||
begin
|
begin
|
||||||
|
@@ -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}"
|
||||||
|
@@ -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)
|
||||||
|
@@ -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]]
|
||||||
|
@@ -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]]
|
||||||
|
@@ -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
|
||||||
|
@@ -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)
|
||||||
|
@@ -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])
|
||||||
|
@@ -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)
|
||||||
|
@@ -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(" ", "_")
|
||||||
|
@@ -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)
|
||||||
|
@@ -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
|
||||||
|
@@ -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 = []
|
||||||
|
@@ -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'
|
||||||
|
|
||||||
|
@@ -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
|
||||||
|
@@ -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
|
||||||
|
@@ -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
|
||||||
|
@@ -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.
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
module TagTypeMethods
|
module Tag::TypeMethods
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
attr_accessor :type_map
|
attr_accessor :type_map
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user