Fix Naming/UncommunicativeMethodParamName lint (#501)

* Fix Naming/UncommunicativeMethodParamName

* code climate
This commit is contained in:
Kohei Sugi 2018-09-05 07:00:26 +09:00 committed by Mac Siri
parent 044be9e162
commit 1ccfdd4651
5 changed files with 81 additions and 71 deletions

View file

@ -36,25 +36,28 @@ class FollowedArticlesController < ApplicationController
(article.decorate.cached_tag_list_array.include?("hiring") && current_user.cached_followed_tag_names.exclude?("hiring"))
end
def article_json(a)
Rails.cache.fetch("article_json-#{a.id}-#{a.updated_at}-#{a.comments_count}-#{a.reactions_count}", expires_in: 30.minutes) do
def article_json(article)
cache_key = "article_json-#{article.id}-#{article.updated_at}" \
"-#{article.comments_count}-#{article.reactions_count}"
Rails.cache.fetch(cache_key, expires_in: 30.minutes) do
{
id: a.id,
path: a.path,
tag_list: a.decorate.cached_tag_list_array,
title: a.title,
published_at_int: a.published_at.to_i,
published_at_month_day: a.published_at.strftime("%B #{a.published_at.day.ordinalize}"),
is_classic: a.published_at < 7.days.ago,
comments_count: a.comments_count,
reactions_count: a.positive_reactions_count,
language: a.language,
id: article.id,
path: article.path,
tag_list: article.decorate.cached_tag_list_array,
title: article.title,
published_at_int: article.published_at.to_i,
published_at_month_day: article.published_at.
strftime("%B #{article.published_at.day.ordinalize}"),
is_classic: article.published_at < 7.days.ago,
comments_count: article.comments_count,
reactions_count: article.positive_reactions_count,
language: article.language,
user: {
name: a.user.name,
username: a.user.username,
profile_image_90: ProfileImage.new(a.user).get(90),
name: article.user.name,
username: article.user.username,
profile_image_90: ProfileImage.new(article.user).get(90),
},
flare_tag: FlareTag.new(a).tag_hash,
flare_tag: FlareTag.new(article).tag_hash,
}
end
end

View file

@ -91,9 +91,9 @@ class MailchimpBot
Digest::MD5.hexdigest(email.downcase)
end
def report_error(e)
def report_error(exception)
logger = Logger.new(STDOUT)
logger.error(e)
logger.error(exception)
end
def target_md5_email

View file

@ -43,16 +43,16 @@ class PodcastFeed
ep.save!
end
def update_existing_episode(ep, item, _podcast)
if ep.published_at == nil
def update_existing_episode(episode, item, _podcast)
if episode.published_at == nil
begin
ep.published_at = item.pubDate.to_date
ep.save
episode.published_at = item.pubDate.to_date
episode.save
rescue StandardError
puts "not valid date"
end
end
update_media_url(ep, item)
update_media_url(episode, item)
end
def existing_episode(item, podcast)
@ -63,29 +63,30 @@ class PodcastFeed
(podcast.unique_website_url? && PodcastEpisode.where(website_url: item.link).presence)
end
def get_media_url(ep, item, podcast)
ep.media_url = if Rails.env.test? ||
def get_media_url(episode, item, podcast)
episode.media_url = if Rails.env.test? ||
open(item.enclosure.url.gsub(/http:/, "https:")).status[0] == "200"
item.enclosure.url.gsub(/http:/, "https:")
else
item.enclosure.url
end
item.enclosure.url.gsub(/http:/, "https:")
else
item.enclosure.url
end
rescue StandardError
# podcast episode must have a media_url
ep.media_url = item.enclosure.url
episode.media_url = item.enclosure.url
if podcast.status_notice.empty?
podcast.update(status_notice: "This podcast may not be playable in the browser")
end
end
def update_media_url(ep, item)
if ep.media_url.include?("https")
def update_media_url(episode, item)
if episode.media_url.include?("https")
nil
elsif !ep.media_url.include?("https") &&
elsif !episode.media_url.include?("https") &&
item.enclosure.url.include?("https")
ep.update!(media_url: item.enclosure.url)
episode.update!(media_url: item.enclosure.url)
end
rescue StandardError
logger.info "something went wrong with #{podcast.title}, #{ep.title} -- #{ep.media_url}"
message = "something went wrong with #{podcast.title}, #{episode.title} -- #{episode.media_url}"
logger.info message
end
end

View file

@ -145,14 +145,14 @@ class ChatChannel < ApplicationRecord
mod_users.pluck(:id)
end
def user_obj(m, i)
def user_obj(membership, index)
{
profile_image: i < 11 ? ProfileImage.new(m.user).get(90) : nil,
darker_color: m.user.decorate.darker_color,
name: m.user.name,
last_opened_at: m.last_opened_at,
username: m.user.username,
id: m.user_id,
profile_image: index < 11 ? ProfileImage.new(membership.user).get(90) : nil,
darker_color: membership.user.decorate.darker_color,
name: membership.user.name,
last_opened_at: membership.last_opened_at,
username: membership.user.username,
id: membership.user_id,
}
end
end

View file

@ -42,7 +42,8 @@ class Tweet < ApplicationRecord
end
hashtags_serialized.each do |tag|
tag_text = tag[:text]
text.gsub!("#" + tag_text, "<a href='https://twitter.com/hashtag/#{tag_text}'>#{'#' + tag_text}</a>")
text.gsub!("#" + tag_text,
"<a href='https://twitter.com/hashtag/#{tag_text}'>#{'#' + tag_text}</a>")
end
if extended_entities_serialized && extended_entities_serialized[:media]
@ -63,35 +64,40 @@ class Tweet < ApplicationRecord
make_tweet_from_api_object(t)
end
def self.make_tweet_from_api_object(t)
t = TwitterBot.new(random_identity).client.status(t.attrs[:retweeted_status][:id_str]) if t.attrs[:retweeted_status]
tweet = Tweet.where(twitter_id_code: t.attrs[:id_str]).first_or_initialize
tweet.twitter_uid = t.user.id.to_s
tweet.twitter_username = t.user.screen_name.downcase
tweet.user_id = User.find_by_twitter_username(t.user.screen_name).try(:id)
tweet.favorite_count = t.favorite_count
tweet.retweet_count = t.retweet_count
tweet.in_reply_to_user_id_code = t.attrs[:in_reply_to_user_id_str]
tweet.in_reply_to_user_id_code = t.attrs[:in_reply_to_status_id_str]
tweet.twitter_user_following_count = t.user.friends_count
tweet.twitter_user_followers_count = t.user.followers_count
tweet.twitter_id_code = t.attrs[:id_str]
tweet.quoted_tweet_id_code = t.attrs[:quoted_status_id_str]
tweet.in_reply_to_username = t.in_reply_to_screen_name
tweet.source = t.source
tweet.text = t.attrs[:full_text]
tweet.twitter_name = t.user.name
tweet.mentioned_usernames_serialized = t.user_mentions.as_json
tweet.hashtags_serialized = t.attrs[:entities][:hashtags]
tweet.remote_profile_image_url = t.user.profile_image_url
tweet.urls_serialized = t.attrs[:entities][:urls]
tweet.media_serialized = t.attrs[:media]
tweet.extended_entities_serialized = t.attrs[:extended_entities]
tweet.full_fetched_object_serialized = t.attrs
tweet.tweeted_at = t.attrs[:created_at]
def self.make_tweet_from_api_object(tweeted)
twitter_bot = TwitterBot.new(random_identity)
tweeted = if tweeted.attrs[:retweeted_status]
twitter_bot.client.status(tweeted.attrs[:retweeted_status][:id_str])
else
tweeted
end
tweet = Tweet.where(twitter_id_code: tweeted.attrs[:id_str]).first_or_initialize
tweet.twitter_uid = tweeted.user.id.to_s
tweet.twitter_username = tweeted.user.screen_name.downcase
tweet.user_id = User.find_by_twitter_username(tweeted.user.screen_name).try(:id)
tweet.favorite_count = tweeted.favorite_count
tweet.retweet_count = tweeted.retweet_count
tweet.in_reply_to_user_id_code = tweeted.attrs[:in_reply_to_user_id_str]
tweet.in_reply_to_user_id_code = tweeted.attrs[:in_reply_to_status_id_str]
tweet.twitter_user_following_count = tweeted.user.friends_count
tweet.twitter_user_followers_count = tweeted.user.followers_count
tweet.twitter_id_code = tweeted.attrs[:id_str]
tweet.quoted_tweet_id_code = tweeted.attrs[:quoted_status_id_str]
tweet.in_reply_to_username = tweeted.in_reply_to_screen_name
tweet.source = tweeted.source
tweet.text = tweeted.attrs[:full_text]
tweet.twitter_name = tweeted.user.name
tweet.mentioned_usernames_serialized = tweeted.user_mentions.as_json
tweet.hashtags_serialized = tweeted.attrs[:entities][:hashtags]
tweet.remote_profile_image_url = tweeted.user.profile_image_url
tweet.urls_serialized = tweeted.attrs[:entities][:urls]
tweet.media_serialized = tweeted.attrs[:media]
tweet.extended_entities_serialized = tweeted.attrs[:extended_entities]
tweet.full_fetched_object_serialized = tweeted.attrs
tweet.tweeted_at = tweeted.attrs[:created_at]
tweet.last_fetched_at = Time.now
tweet.user_is_verified = t.user.verified?
tweet.is_quote_status = t.attrs[:is_quote_status]
tweet.user_is_verified = tweeted.user.verified?
tweet.is_quote_status = tweeted.attrs[:is_quote_status]
tweet.save!
tweet
end