From 697bbea8a26b2d87afaefb68a09e548e8caef17f Mon Sep 17 00:00:00 2001 From: edogawaconan Date: Sat, 23 Aug 2014 09:45:32 +0900 Subject: [PATCH] Replace explicit require with autoloader. --- app/models/post.rb | 32 +++++++++---------- app/models/post/api_methods.rb | 2 +- app/models/post/cache_methods.rb | 2 +- app/models/post/change_sequence_methods.rb | 2 +- app/models/post/comment_methods.rb | 2 +- app/models/post/count_methods.rb | 2 +- app/models/post/file_methods.rb | 2 +- app/models/post/frame_methods.rb | 2 +- app/models/post/image_store/amazon_s3.rb | 2 +- app/models/post/image_store/local_flat.rb | 2 +- .../local_flat_with_amazon_s3_backup.rb | 2 +- .../post/image_store/local_hierarchy.rb | 2 +- .../post/image_store/remote_hierarchy.rb | 4 +-- app/models/post/image_store_methods.rb | 18 +++++++---- app/models/post/mirror_methods.rb | 2 +- app/models/post/parent_methods.rb | 2 +- app/models/post/rating_methods.rb | 2 +- app/models/post/sql_methods.rb | 2 +- app/models/post/status_methods.rb | 2 +- app/models/post/tag_methods.rb | 2 +- app/models/post/vote_methods.rb | 2 +- app/models/tag.rb | 12 +++---- app/models/tag/api_methods.rb | 2 +- app/models/tag/cache_methods.rb | 2 +- app/models/tag/parse_methods.rb | 2 +- app/models/tag/related_tag_methods.rb | 2 +- app/models/tag/type_methods.rb | 2 +- 27 files changed, 56 insertions(+), 56 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 03eac954..235c8065 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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 diff --git a/app/models/post/api_methods.rb b/app/models/post/api_methods.rb index f2c30a9b..73e4d2d9 100644 --- a/app/models/post/api_methods.rb +++ b/app/models/post/api_methods.rb @@ -1,4 +1,4 @@ -module PostApiMethods +module Post::ApiMethods attr_accessor :similarity def api_attributes diff --git a/app/models/post/cache_methods.rb b/app/models/post/cache_methods.rb index dba4c41b..631f5333 100644 --- a/app/models/post/cache_methods.rb +++ b/app/models/post/cache_methods.rb @@ -1,4 +1,4 @@ -module PostCacheMethods +module Post::CacheMethods def self.included(m) m.after_save :expire_cache m.after_destroy :expire_cache diff --git a/app/models/post/change_sequence_methods.rb b/app/models/post/change_sequence_methods.rb index 57175a57..8dd55957 100644 --- a/app/models/post/change_sequence_methods.rb +++ b/app/models/post/change_sequence_methods.rb @@ -1,4 +1,4 @@ -module PostChangeSequenceMethods +module Post::ChangeSequenceMethods attr_accessor :increment_change_seq def self.included(m) diff --git a/app/models/post/comment_methods.rb b/app/models/post/comment_methods.rb index d4cf8c93..453a8fd8 100644 --- a/app/models/post/comment_methods.rb +++ b/app/models/post/comment_methods.rb @@ -1,4 +1,4 @@ -module PostCommentMethods +module Post::CommentMethods def self.included(m) m.has_many :comments, lambda { order "id" } end diff --git a/app/models/post/count_methods.rb b/app/models/post/count_methods.rb index 4c5f5884..8611cf37 100644 --- a/app/models/post/count_methods.rb +++ b/app/models/post/count_methods.rb @@ -1,4 +1,4 @@ -module PostCountMethods +module Post::CountMethods module ClassMethods def fast_count(tags = nil) # A small sanitation diff --git a/app/models/post/file_methods.rb b/app/models/post/file_methods.rb index a72630a4..d79905c9 100644 --- a/app/models/post/file_methods.rb +++ b/app/models/post/file_methods.rb @@ -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 diff --git a/app/models/post/frame_methods.rb b/app/models/post/frame_methods.rb index 5a4aad6f..c34a6a55 100644 --- a/app/models/post/frame_methods.rb +++ b/app/models/post/frame_methods.rb @@ -1,4 +1,4 @@ -module PostFrameMethods +module Post::FrameMethods def self.included(m) m.versioned :frames_pending, :default => "", :allow_reverting_to_default => true end diff --git a/app/models/post/image_store/amazon_s3.rb b/app/models/post/image_store/amazon_s3.rb index 0d87d3b8..c575da8d 100644 --- a/app/models/post/image_store/amazon_s3.rb +++ b/app/models/post/image_store/amazon_s3.rb @@ -1,4 +1,4 @@ -module PostImageStoreMethods +module Post::ImageStore module AmazonS3 def move_file begin diff --git a/app/models/post/image_store/local_flat.rb b/app/models/post/image_store/local_flat.rb index 9c275f96..2f0af22a 100644 --- a/app/models/post/image_store/local_flat.rb +++ b/app/models/post/image_store/local_flat.rb @@ -1,4 +1,4 @@ -module PostImageStoreMethods +module Post::ImageStore module LocalFlat def file_path "#{Rails.root}/public/data/#{file_name}" diff --git a/app/models/post/image_store/local_flat_with_amazon_s3_backup.rb b/app/models/post/image_store/local_flat_with_amazon_s3_backup.rb index 1f42ac06..1b04213c 100644 --- a/app/models/post/image_store/local_flat_with_amazon_s3_backup.rb +++ b/app/models/post/image_store/local_flat_with_amazon_s3_backup.rb @@ -1,4 +1,4 @@ -module PostImageStoreMethods +module Post::ImageStore module LocalFlatWithAmazonS3Backup def move_file FileUtils.mv(tempfile_path, file_path) diff --git a/app/models/post/image_store/local_hierarchy.rb b/app/models/post/image_store/local_hierarchy.rb index ac455042..fe6d30c6 100644 --- a/app/models/post/image_store/local_hierarchy.rb +++ b/app/models/post/image_store/local_hierarchy.rb @@ -1,4 +1,4 @@ -module PostImageStoreMethods +module Post::ImageStore module LocalHierarchy def file_hierarchy "%s/%s" % [md5[0,2], md5[2,2]] diff --git a/app/models/post/image_store/remote_hierarchy.rb b/app/models/post/image_store/remote_hierarchy.rb index 3882818d..51b19bc8 100644 --- a/app/models/post/image_store/remote_hierarchy.rb +++ b/app/models/post/image_store/remote_hierarchy.rb @@ -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]] diff --git a/app/models/post/image_store_methods.rb b/app/models/post/image_store_methods.rb index 2b9edca3..1003e64c 100644 --- a/app/models/post/image_store_methods.rb +++ b/app/models/post/image_store_methods.rb @@ -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 diff --git a/app/models/post/mirror_methods.rb b/app/models/post/mirror_methods.rb index 74db11c7..7ce647fb 100644 --- a/app/models/post/mirror_methods.rb +++ b/app/models/post/mirror_methods.rb @@ -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) diff --git a/app/models/post/parent_methods.rb b/app/models/post/parent_methods.rb index cb2b04bf..b7ad03a1 100644 --- a/app/models/post/parent_methods.rb +++ b/app/models/post/parent_methods.rb @@ -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]) diff --git a/app/models/post/rating_methods.rb b/app/models/post/rating_methods.rb index 0ae26b98..df5b2257 100644 --- a/app/models/post/rating_methods.rb +++ b/app/models/post/rating_methods.rb @@ -1,4 +1,4 @@ -module PostRatingMethods +module Post::RatingMethods attr_accessor :old_rating def self.included(m) diff --git a/app/models/post/sql_methods.rb b/app/models/post/sql_methods.rb index 88313a94..af40ca40 100644 --- a/app/models/post/sql_methods.rb +++ b/app/models/post/sql_methods.rb @@ -1,4 +1,4 @@ -module PostSqlMethods +module Post::SqlMethods module ClassMethods def find_by_tag_join(tag, options = {}) tag = tag.downcase.tr(" ", "_") diff --git a/app/models/post/status_methods.rb b/app/models/post/status_methods.rb index 4403c95e..4179d6d3 100644 --- a/app/models/post/status_methods.rb +++ b/app/models/post/status_methods.rb @@ -1,4 +1,4 @@ -module PostStatusMethods +module Post::StatusMethods def status=(s) return if s == status write_attribute(:status, s) diff --git a/app/models/post/tag_methods.rb b/app/models/post/tag_methods.rb index 1e4dc51c..81118de6 100644 --- a/app/models/post/tag_methods.rb +++ b/app/models/post/tag_methods.rb @@ -1,4 +1,4 @@ -module PostTagMethods +module Post::TagMethods attr_accessor :tags, :new_tags, :old_tags, :old_cached_tags module ClassMethods diff --git a/app/models/post/vote_methods.rb b/app/models/post/vote_methods.rb index 5387b730..d72ce944 100644 --- a/app/models/post/vote_methods.rb +++ b/app/models/post/vote_methods.rb @@ -1,4 +1,4 @@ -module PostVoteMethods +module Post::VoteMethods module ClassMethods def recalculate_score(id=nil) conds = [] diff --git a/app/models/tag.rb b/app/models/tag.rb index 00fb6976..f1eab217 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -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' diff --git a/app/models/tag/api_methods.rb b/app/models/tag/api_methods.rb index 33adfb68..326c89d7 100644 --- a/app/models/tag/api_methods.rb +++ b/app/models/tag/api_methods.rb @@ -1,4 +1,4 @@ -module TagApiMethods +module Tag::ApiMethods def self.included(m) m.extend(ClassMethods) end diff --git a/app/models/tag/cache_methods.rb b/app/models/tag/cache_methods.rb index 019ff4c5..a062e340 100644 --- a/app/models/tag/cache_methods.rb +++ b/app/models/tag/cache_methods.rb @@ -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 diff --git a/app/models/tag/parse_methods.rb b/app/models/tag/parse_methods.rb index 970ce68f..82a60a0c 100644 --- a/app/models/tag/parse_methods.rb +++ b/app/models/tag/parse_methods.rb @@ -1,4 +1,4 @@ -module TagParseMethods +module Tag::ParseMethods module ClassMethods def scan_query(query) query.to_s.to_valid_utf8.downcase.split.uniq diff --git a/app/models/tag/related_tag_methods.rb b/app/models/tag/related_tag_methods.rb index 03072884..864e05e5 100644 --- a/app/models/tag/related_tag_methods.rb +++ b/app/models/tag/related_tag_methods.rb @@ -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. diff --git a/app/models/tag/type_methods.rb b/app/models/tag/type_methods.rb index cb6edcec..925910a9 100644 --- a/app/models/tag/type_methods.rb +++ b/app/models/tag/type_methods.rb @@ -1,4 +1,4 @@ -module TagTypeMethods +module Tag::TypeMethods module ClassMethods attr_accessor :type_map