Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

style: 💄 $ rubocop -A app/controllers #128

Merged
merged 1 commit into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# inherit_from: .rubocop_todo.yml

require:
- rubocop-rails

AllCops:
NewCops: enable
DisplayCopNames: true
Exclude:
- 'vendor/**/*'
- 'node_modules/**/*'
- 'spec/**/*'
- 'db/schema.rb'
- 'db/**/*'
- 'config/**/*'
- 'Guardfile'
- 'bin/**/*'
- 'tmp/**/*'

Style/Documentation:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: false

Style/StringLiterals:
EnforcedStyle: single_quotes

Style/StringLiteralsInInterpolation:
EnforcedStyle: single_quotes

Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma

Metrics/BlockLength:
Max: 52

Metrics/ClassLength:
Max: 500

Metrics/CyclomaticComplexity:
Max: 16

Metrics/MethodLength:
Max: 65

Metrics/PerceivedComplexity:
Max: 17

Metrics/ModuleLength:
Max: 160
19 changes: 10 additions & 9 deletions app/controllers/after_party_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,24 @@ def index
end

private
def after_party_get_method

def after_party_get_method # rubocop:disable Metrics/AbcSize
# ex. https://twitter.com/nyaka_y/status/874979736308416512
all_records = Hashtag.all.map { |rec| rec.attributes }
all_records = Hashtag.all.map(&:attributes)
@all_rec_tweet_ids = []
all_records.each do |record|
@all_rec_tweet_ids << record["tweet_id"]
@all_rec_tweet_ids << record['tweet_id']
end

tag_records = Hashtag.where(tagname: "幻水総選挙2017後夜祭").map { |rec| rec.attributes }
tag_records = Hashtag.where(tagname: '幻水総選挙2017後夜祭').map(&:attributes)
@tag_rec_tweet_ids = []
tag_records.each do |record|
@tag_rec_tweet_ids << record["tweet_id"]
@tag_rec_tweet_ids << record['tweet_id']
end

@result_ids = []
@tag_rec_tweet_ids.each do |tweet_id|
# if @all_rec_tweet_ids.count(tweet_id) == 1
@result_ids << tweet_id
# end
@result_ids << tweet_id
end

# tomochin = without_retweets_and_gensosenkyo_loose_limited_period # Array
Expand All @@ -54,6 +53,8 @@ def after_party_get_method
end

@kaminari_page_per = 20
@kaminaried_tweets = Kaminari.paginate_array(last_result_tweets).page(params[:page]).per(@kaminari_page_per) # HACK: 個別に設定を決めないようにする

# HACK: 個別に設定を決めないようにする
@kaminaried_tweets = Kaminari.paginate_array(last_result_tweets).page(params[:page]).per(@kaminari_page_per)
end
end
9 changes: 4 additions & 5 deletions app/controllers/check_vote_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ class CheckVoteController < ApplicationController
include TweetsJoinUsers
include SelectTweetsByHashtag

def index
end
def index; end

def result
@screen_name = params[:screen_name].nil? ? "" : params[:screen_name].gsub(/@/, "")
def result # rubocop:disable Metrics/AbcSize
@screen_name = params[:screen_name].nil? ? '' : params[:screen_name].gsub(/@/, '')

# tweets_by_specific_user = tweets_by_specific_user(@screen_name)
# tweets_by_specific_user = tweets_by_specific_user_limited_period(@screen_name)
tweets_by_specific_user = tweets_by_specific_user_limited_loose_period(@screen_name)
select_tweets_by_hashtag = select_tweets_by_hashtag(tweets_by_specific_user, "幻水総選挙2017投票", "幻水総選挙2017")
select_tweets_by_hashtag = select_tweets_by_hashtag(tweets_by_specific_user, '幻水総選挙2017投票', '幻水総選挙2017')

# TODO: コントローラに詰め込みすぎ
unreadable_tweet_ids = IsReadableTweet.where(is_readable: false)
Expand Down
16 changes: 10 additions & 6 deletions app/controllers/concerns/for_get_method_at_members.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ForGetMethodAtMembers
def show_vote_result
def show_vote_result # rubocop:disable Metrics/AbcSize
source_tweets = without_retweets_and_gensosenkyo_loose_limited_period
selected_tweets = select_tweets_by_hashtag(source_tweets, "幻水総選挙2017投票")
selected_tweets = select_tweets_by_hashtag(source_tweets, '幻水総選挙2017投票')

# TODO: コントローラに詰め込みすぎ
unreadable_tweet_ids = IsReadableTweet.where(is_readable: false)
Expand All @@ -15,12 +15,14 @@ def show_vote_result
end

@kaminari_page_per = 20
@kaminaried_tweets = Kaminari.paginate_array(result_tweets.reverse).page(params[:page]).per(@kaminari_page_per) # HACK: 個別に設定を決めないようにする

# HACK: 個別に設定を決めないようにする
@kaminaried_tweets = Kaminari.paginate_array(result_tweets.reverse).page(params[:page]).per(@kaminari_page_per)
end

def show_vote_result_after_party
def show_vote_result_after_party # rubocop:disable Metrics/AbcSize
source_tweets = for_after_party
selected_tweets = select_tweets_by_hashtag(source_tweets, "幻水総選挙2017後夜祭")
selected_tweets = select_tweets_by_hashtag(source_tweets, '幻水総選挙2017後夜祭')

# TODO: コントローラに詰め込みすぎ
unreadable_tweet_ids = IsReadableTweet.where(is_readable: false)
Expand All @@ -34,6 +36,8 @@ def show_vote_result_after_party
end

@kaminari_page_per = 20
@kaminaried_tweets = Kaminari.paginate_array(result_tweets.reverse).page(params[:page]).per(@kaminari_page_per) # HACK: 個別に設定を決めないようにする

# HACK: 個別に設定を決めないようにする
@kaminaried_tweets = Kaminari.paginate_array(result_tweets.reverse).page(params[:page]).per(@kaminari_page_per)
end
end
11 changes: 8 additions & 3 deletions app/controllers/concerns/for_post_method_at_members.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ForPostMethodAtMembers
def show_vote_result_with_search(serach_word)
def show_vote_result_with_search(serach_word) # rubocop:disable Metrics/AbcSize
source_tweets = without_retweets_and_gensosenkyo_loose_limited_period
selected_tweets = select_tweets_by_hashtag(source_tweets, "幻水総選挙2017投票")
selected_tweets = select_tweets_by_hashtag(source_tweets, '幻水総選挙2017投票')

# TODO: コントローラに詰め込みすぎ
unreadable_tweet_ids = IsReadableTweet.where(is_readable: false)
Expand All @@ -21,6 +21,11 @@ def show_vote_result_with_search(serach_word)
end

@kaminari_page_per = 20
@kaminaried_tweets = Kaminari.paginate_array(@last_result_tweets.reverse).page(params[:page]).per(@kaminari_page_per) # HACK: 個別に設定を決めないようにする

# HACK: 個別に設定を決めないようにする
@kaminaried_tweets = Kaminari
.paginate_array(@last_result_tweets.reverse)
.page(params[:page])
.per(@kaminari_page_per)
end
end
7 changes: 5 additions & 2 deletions app/controllers/concerns/select_tweets_by_hashtag.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
module SelectTweetsByHashtag
# HACK: 引数 hashtag は、複数の値を取れるようにする(現状は場当たり的にも程がある)
def select_tweets_by_hashtag(tweets, hashtag_a, hashtag_b="")
def select_tweets_by_hashtag(tweets, hashtag_a, hashtag_b = '')
@selected_tweets = []

tweets.each do |tweet|
target_tweets = Hashtag.where(tweet_id: tweet.tweet_id)
target_tweets.each do |target_tweet|

target_tweets.each do |target_tweet| # rubocop:disable Lint/UnreachableLoop (FIXME:)
@selected_tweets << tweet if target_tweet.tagname == hashtag_a || target_tweet.tagname == hashtag_b

break # TODO: 「どちらかが含まれていた時点で終了」ということであるが、論理的に複雑である
end
end
Expand Down
32 changes: 21 additions & 11 deletions app/controllers/concerns/tweets_join_users.rb
Original file line number Diff line number Diff line change
@@ -1,51 +1,61 @@
# rubocop:disable Layout/LineLength
module TweetsJoinUsers
# TODO: find_by_sql は良くない
def without_retweets
Tweet.find_by_sql([%Q{SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE is_retweet = false ORDER BY tweets.tweeted_at DESC}])
Tweet.find_by_sql([%(SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE is_retweet = false ORDER BY tweets.tweeted_at DESC)])
end

# TODO: find_by_sql は良くない
# TODO: NOT DRY
def without_retweets_and_limited_period
Tweet.find_by_sql([%Q{SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE (is_retweet = false) AND (tweeted_at BETWEEN '2017/06/16 12:00:00' AND '2017/06/18 00:00:00') ORDER BY tweets.tweeted_at DESC}])
Tweet.find_by_sql([%{SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE (is_retweet = false) AND (tweeted_at BETWEEN '2017/06/16 12:00:00' AND '2017/06/18 00:00:00') ORDER BY tweets.tweeted_at DESC}])
end

def without_retweets_and_loose_limited_period
Tweet.find_by_sql([%Q{SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE (is_retweet = false) AND (tweeted_at BETWEEN '2017/06/16 11:45:00' AND '2017/06/18 03:00:00') ORDER BY tweets.tweeted_at DESC}])
Tweet.find_by_sql([%{SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE (is_retweet = false) AND (tweeted_at BETWEEN '2017/06/16 11:45:00' AND '2017/06/18 03:00:00') ORDER BY tweets.tweeted_at DESC}])
end

def without_retweets_and_gensosenkyo_loose_limited_period
Tweet.find_by_sql([%Q{SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE (is_retweet = false) AND (users.screen_name != 'gensosenkyo') AND (tweeted_at BETWEEN '2017/06/16 11:45:00' AND '2017/06/18 03:00:00') ORDER BY tweets.tweeted_at DESC}])
Tweet.find_by_sql([%{SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE (is_retweet = false) AND (users.screen_name != 'gensosenkyo') AND (tweeted_at BETWEEN '2017/06/16 11:45:00' AND '2017/06/18 03:00:00') ORDER BY tweets.tweeted_at DESC}])
end

def without_retweets_and_gensosenkyo_loose_limited_period_name_sort
Tweet.find_by_sql([%Q{SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE (is_retweet = false) AND (users.screen_name != 'gensosenkyo') AND (tweeted_at BETWEEN '2017/06/16 11:45:00' AND '2017/06/18 03:00:00') ORDER BY users.screen_name ASC}])
Tweet.find_by_sql([%{SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE (is_retweet = false) AND (users.screen_name != 'gensosenkyo') AND (tweeted_at BETWEEN '2017/06/16 11:45:00' AND '2017/06/18 03:00:00') ORDER BY users.screen_name ASC}])
end

def for_after_party
Tweet.find_by_sql([%Q{SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE (is_retweet = false) AND (tweeted_at > '2017/06/24 11:45:00') ORDER BY tweets.tweeted_at DESC}])
Tweet.find_by_sql([%{SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE (is_retweet = false) AND (tweeted_at > '2017/06/24 11:45:00') ORDER BY tweets.tweeted_at DESC}])
end

# TODO: find_by_sql は良くない
def tweets_by_specific_user(screen_name)
Tweet.find_by_sql([%Q{SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE screen_name = ? AND is_retweet = false ORDER BY tweets.tweeted_at DESC}, screen_name])
Tweet.find_by_sql([
%(SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE screen_name = ? AND is_retweet = false ORDER BY tweets.tweeted_at DESC), screen_name
])
end

# TODO: find_by_sql は良くない
# TODO: NOT DRY
def tweets_by_specific_user_limited_period(screen_name)
Tweet.find_by_sql([%Q{SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE (screen_name = ?) AND (is_retweet = false) AND (tweeted_at BETWEEN '2017/06/16 12:00:00' AND '2017/06/18 00:00:00') ORDER BY tweets.tweeted_at DESC}, screen_name])
Tweet.find_by_sql([
%{SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE (screen_name = ?) AND (is_retweet = false) AND (tweeted_at BETWEEN '2017/06/16 12:00:00' AND '2017/06/18 00:00:00') ORDER BY tweets.tweeted_at DESC}, screen_name
])
end

def tweets_by_specific_user_limited_loose_period(screen_name)
Tweet.find_by_sql([%Q{SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE (screen_name = ?) AND (is_retweet = false) AND (tweeted_at BETWEEN '2017/06/16 11:45:00' AND '2017/06/18 03:00:00') ORDER BY tweets.tweeted_at DESC}, screen_name])
Tweet.find_by_sql([
%{SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE (screen_name = ?) AND (is_retweet = false) AND (tweeted_at BETWEEN '2017/06/16 11:45:00' AND '2017/06/18 03:00:00') ORDER BY tweets.tweeted_at DESC}, screen_name
])
end

def tweets_by_specific_user_limited_count_vote_period(screen_name)
Tweet.find_by_sql([%Q{SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE (screen_name = ?) AND (is_retweet = false) AND (tweeted_at BETWEEN '2017/06/25 02:45:00' AND '2017/06/25 10:00:00') ORDER BY tweets.tweeted_at ASC}, screen_name])
Tweet.find_by_sql([
%{SELECT * FROM tweets INNER JOIN users ON tweets.user_id = users.user_id WHERE (screen_name = ?) AND (is_retweet = false) AND (tweeted_at BETWEEN '2017/06/25 02:45:00' AND '2017/06/25 10:00:00') ORDER BY tweets.tweeted_at ASC}, screen_name
])
end

def attached_image_uri(target_tweet_id)
Tweet.find_by_sql([%Q{SELECT * FROM attached_images WHERE tweet_id = ? ORDER BY media_id ASC}, target_tweet_id])
Tweet.find_by_sql([%(SELECT * FROM attached_images WHERE tweet_id = ? ORDER BY media_id ASC), target_tweet_id])
end
end
# rubocop:enable Layout/LineLength
7 changes: 5 additions & 2 deletions app/controllers/count_vote_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ def index
end

private

# hyper dirty code...
def show_count_vote_tweet
source_tweets = tweets_by_specific_user_limited_count_vote_period("gensosenkyo")
source_tweets = tweets_by_specific_user_limited_count_vote_period('gensosenkyo')
result_tweets = source_tweets

@kaminari_page_per = 10
@kaminaried_tweets = Kaminari.paginate_array(result_tweets).page(params[:page]).per(@kaminari_page_per) # HACK: 個別に設定を決めないようにする

# HACK: 個別に設定を決めないようにする
@kaminaried_tweets = Kaminari.paginate_array(result_tweets).page(params[:page]).per(@kaminari_page_per)
end
end
16 changes: 12 additions & 4 deletions app/controllers/for_members_all_vote_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ class ForMembersAllVoteController < ApplicationController
layout 'application_members'

def index
authenticate_or_request_with_http_basic("Hello, gensosenkyo staff!") do |username, password|
authenticate_or_request_with_http_basic('Hello, gensosenkyo staff!') do |username, password|
username == ENV['MEMBERS_PAGE_AUTH_USERNAME'] && password == ENV['MEMBERS_PAGE_AUTH_PASSWORD']
end

for_get_method if request.get?
for_post_method(params[:search_word]) if request.post?
end
Expand All @@ -29,10 +30,12 @@ def for_get_method
end

@kaminari_page_per = 20
@kaminaried_tweets = Kaminari.paginate_array(last_result_tweets.reverse).page(params[:page]).per(@kaminari_page_per) # HACK: 個別に設定を決めないようにする

# HACK: 個別に設定を決めないようにする
@kaminaried_tweets = Kaminari.paginate_array(last_result_tweets.reverse).page(params[:page]).per(@kaminari_page_per)
end

def for_post_method(search_word)
def for_post_method(search_word) # rubocop:disable Metrics/AbcSize
source_tweets = without_retweets

# TODO: コントローラに詰め込みすぎ
Expand All @@ -53,6 +56,11 @@ def for_post_method(search_word)
end

@kaminari_page_per = 20
@kaminaried_tweets = Kaminari.paginate_array(@lastest_result_tweets.reverse).page(params[:page]).per(@kaminari_page_per) # HACK: 個別に設定を決めないようにする

# HACK: 個別に設定を決めないようにする
@kaminaried_tweets = Kaminari
.paginate_array(@lastest_result_tweets.reverse)
.page(params[:page])
.per(@kaminari_page_per)
end
end
20 changes: 12 additions & 8 deletions app/controllers/for_members_check_vote_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ class ForMembersCheckVoteController < ApplicationController
layout 'application_members'
# before_action :site_http_basic_authenticate_with

def show
authenticate_or_request_with_http_basic("Hello, gensosenkyo staff!") do |username, password|
def show # rubocop:disable Metrics/AbcSize
authenticate_or_request_with_http_basic('Hello, gensosenkyo staff!') do |username, password|
username == ENV['MEMBERS_PAGE_AUTH_USERNAME'] && password == ENV['MEMBERS_PAGE_AUTH_PASSWORD']
end

@screen_name = params[:search_tw_id].nil? ? "" : params[:search_tw_id].gsub(/@/, "")
@screen_name = params[:search_tw_id].nil? ? '' : params[:search_tw_id].gsub(/@/, '')
source_tweets = tweets_by_specific_user(@screen_name)

# TODO: コントローラに詰め込みすぎ
Expand All @@ -27,15 +27,17 @@ def show
end

@kaminari_page_per = 20
@kaminaried_tweets = Kaminari.paginate_array(last_result_tweets.reverse).page(params[:page]).per(@kaminari_page_per) # HACK: 個別に設定を決めないようにする

# HACK: 個別に設定を決めないようにする
@kaminaried_tweets = Kaminari.paginate_array(last_result_tweets.reverse).page(params[:page]).per(@kaminari_page_per)
end

def result
authenticate_or_request_with_http_basic("Hello, gensosenkyo staff!") do |username, password|
def result # rubocop:disable Metrics/AbcSize
authenticate_or_request_with_http_basic('Hello, gensosenkyo staff!') do |username, password|
username == ENV['MEMBERS_PAGE_AUTH_USERNAME'] && password == ENV['MEMBERS_PAGE_AUTH_PASSWORD']
end

@screen_name = params[:search_tw_id].nil? ? "" : params[:search_tw_id].gsub(/@/, "")
@screen_name = params[:search_tw_id].nil? ? '' : params[:search_tw_id].gsub(/@/, '')
source_tweets = tweets_by_specific_user(@screen_name)

# TODO: コントローラに詰め込みすぎ
Expand All @@ -50,6 +52,8 @@ def result
end

@kaminari_page_per = 20
@kaminaried_tweets = Kaminari.paginate_array(last_result_tweets.reverse).page(params[:page]).per(@kaminari_page_per) # HACK: 個別に設定を決めないようにする

# HACK: 個別に設定を決めないようにする
@kaminaried_tweets = Kaminari.paginate_array(last_result_tweets.reverse).page(params[:page]).per(@kaminari_page_per)
end
end
5 changes: 2 additions & 3 deletions app/controllers/for_members_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ForMembersController < ApplicationController
before_action :site_http_basic_authenticate_with

def site_http_basic_authenticate_with
authenticate_or_request_with_http_basic("Hello, gensosenkyo staff!") do |username, password|
authenticate_or_request_with_http_basic('Hello, gensosenkyo staff!') do |username, password|
username == ENV['MEMBERS_PAGE_AUTH_USERNAME'] && password == ENV['MEMBERS_PAGE_AUTH_PASSWORD']
end
end
Expand All @@ -18,6 +18,5 @@ def index
# show_vote_result_with_search(params[:search_word]) if request.post?
end

def requirement
end
def requirement; end
end
Loading