Skip to content

Commit

Permalink
appease ChefStyle: Layout/MultilineMethodCallIndentation
Browse files Browse the repository at this point in the history
> Use X (not Y) spaces for indenting an expression spanning multiple lines.

OK. Opted to clean up some of these by bringing the first dotted method
down to a second line so that the entire call chain would be indented.

Signed-off-by: Robb Kidd <rkidd@chef.io>
  • Loading branch information
robbkidd committed Jun 25, 2020
1 parent 413094c commit 258f0b1
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 68 deletions.
Expand Up @@ -89,8 +89,9 @@ def contingent
private

def assign_cookbook
@cookbook = Cookbook.with_name(params[:cookbook])
.includes(:cookbook_versions)
.first!
@cookbook = Cookbook
.with_name(params[:cookbook])
.includes(:cookbook_versions)
.first!
end
end
18 changes: 10 additions & 8 deletions src/supermarket/app/controllers/collaborators_controller.rb
Expand Up @@ -12,9 +12,10 @@ class CollaboratorsController < ApplicationController
# for a given resource.
#
def index
@collaborators = User.includes(:chef_account)
.where.not(id: params[:ineligible_user_ids])
.limit(20)
@collaborators = User
.includes(:chef_account)
.where.not(id: params[:ineligible_user_ids])
.limit(20)

if params[:q]
@collaborators = @collaborators.search(params[:q])
Expand Down Expand Up @@ -146,11 +147,12 @@ def perform_fieri(cookbook)
# Params used when creating one or more +Collaborator+.
#
def collaborator_params
params.require(:collaborator)
.permit(:resourceable_type,
:resourceable_id,
:user_ids,
:group_ids)
params
.require(:collaborator)
.permit(:resourceable_type,
:resourceable_id,
:user_ids,
:group_ids)
end

def group_collaborators(resource, group)
Expand Down
35 changes: 20 additions & 15 deletions src/supermarket/app/controllers/cookbooks_controller.rb
Expand Up @@ -56,18 +56,22 @@ def index
# Return the three most recently updated and created cookbooks.
#
def directory
@recently_updated_cookbooks = Cookbook.order_by_latest_upload_date
.limit(5)
@most_downloaded_cookbooks = Cookbook.includes(:cookbook_versions)
.ordered_by("most_downloaded")
.limit(5)
@most_followed_cookbooks = Cookbook.includes(:cookbook_versions)
.ordered_by("most_followed")
.limit(5)
@featured_cookbooks = Cookbook.includes(:cookbook_versions)
.featured
.order(:name)
.limit(5)
@recently_updated_cookbooks = Cookbook
.order_by_latest_upload_date
.limit(5)
@most_downloaded_cookbooks = Cookbook
.includes(:cookbook_versions)
.ordered_by("most_downloaded")
.limit(5)
@most_followed_cookbooks = Cookbook
.includes(:cookbook_versions)
.ordered_by("most_followed")
.limit(5)
@featured_cookbooks = Cookbook
.includes(:cookbook_versions)
.featured
.order(:name)
.limit(5)

@cookbook_count = Cookbook.count
@user_count = User.count
Expand Down Expand Up @@ -154,9 +158,10 @@ def follow
# Makes the current user unfollow the specified cookbook.
#
def unfollow
cookbook_follower = @cookbook.cookbook_followers
.where(user: current_user)
.first!
cookbook_follower = @cookbook
.cookbook_followers
.where(user: current_user)
.first!
cookbook_follower.destroy
Supermarket::Metrics.increment "cookbook.unfollowed"

Expand Down
7 changes: 4 additions & 3 deletions src/supermarket/app/lib/supermarket/health.rb
Expand Up @@ -56,9 +56,10 @@ def check_features
#
def expired_ocid_tokens
postgres_health_metric do
@supermarket[:expired_ocid_tokens] = Account.for("chef_oauth2")
.where("oauth_expires < ?", Time.current)
.count
@supermarket[:expired_ocid_tokens] = Account
.for("chef_oauth2")
.where("oauth_expires < ?", Time.current)
.count
end
end

Expand Down
17 changes: 9 additions & 8 deletions src/supermarket/app/models/cookbook.rb
Expand Up @@ -333,14 +333,15 @@ def followed_by?(user)
# @return [Array<CookbookDependency>]
#
def contingents
CookbookDependency.includes(cookbook_version: :cookbook)
.where(cookbook_id: id)
.sort_by do |cd|
[
cd.cookbook_version.cookbook.name,
Chef::Version.new(cd.cookbook_version.version)
]
end
CookbookDependency
.includes(cookbook_version: :cookbook)
.where(cookbook_id: id)
.sort_by do |cd|
[
cd.cookbook_version.cookbook.name,
Chef::Version.new(cd.cookbook_version.version)
]
end
end

#
Expand Down
5 changes: 3 additions & 2 deletions src/supermarket/app/models/user.rb
Expand Up @@ -68,8 +68,9 @@ class User < ApplicationRecord
# +SystemEmail+ in question
#
def email_preference_for(name)
email_preferences.includes(:system_email)
.find_by(system_emails: { name: name })
email_preferences
.includes(:system_email)
.find_by(system_emails: { name: name })
end

#
Expand Down
26 changes: 16 additions & 10 deletions src/supermarket/app/workers/cookbook_deletion_worker.rb
Expand Up @@ -11,22 +11,28 @@ class CookbookDeletionWorker
def perform(cookbook)
id = cookbook["id"]

subscribed_user_ids = SystemEmail.find_by!(name: "Cookbook deleted")
.subscribed_users
.pluck(:id)
subscribed_user_ids = SystemEmail
.find_by!(name: "Cookbook deleted")
.subscribed_users
.pluck(:id)

followers_or_collaborators = CookbookFollower.where(cookbook_id: id)
.includes(:user) +
Collaborator.where(resourceable_id: id,
resourceable_type: "Cookbook")
.includes(:user)
follows = CookbookFollower
.where(cookbook_id: id)
.includes(:user)
collaborations = Collaborator
.where(resourceable_id: id, resourceable_type: "Cookbook")
.includes(:user)
follows_and_collaborations = follows + collaborations

users = followers_or_collaborators.map(&:user).uniq.select { |u| subscribed_user_ids.include?(u.id) }
users = follows_and_collaborations
.map(&:user)
.uniq
.select { |u| subscribed_user_ids.include?(u.id) }

users.each do |user|
CookbookMailer.cookbook_deleted_email(cookbook["name"], user).deliver_now
end

followers_or_collaborators.each(&:destroy)
follows_and_collaborations.each(&:destroy)
end
end
7 changes: 4 additions & 3 deletions src/supermarket/app/workers/cookbook_deprecated_notifier.rb
Expand Up @@ -26,9 +26,10 @@ def perform(cookbook_id)
private

def users_to_email(cookbook)
subscribed_user_ids = SystemEmail.find_by!(name: "Cookbook deprecated")
.subscribed_users
.pluck(:id)
subscribed_user_ids = SystemEmail
.find_by!(name: "Cookbook deprecated")
.subscribed_users
.pluck(:id)

users_to_email = []
users_to_email << cookbook.owner
Expand Down
24 changes: 13 additions & 11 deletions src/supermarket/app/workers/cookbook_notify_worker.rb
Expand Up @@ -12,22 +12,24 @@ class CookbookNotifyWorker
def perform(cookbook_version_id)
cookbook_version = CookbookVersion.find(cookbook_version_id)

active_user_ids = User.joins(:accounts)
.where("provider = ? AND oauth_token != ?", "chef_oauth2", "imported")
.pluck(:id)
active_user_ids = User
.joins(:accounts)
.where("provider = ? AND oauth_token != ?", "chef_oauth2", "imported")
.pluck(:id)

subscribed_user_ids = SystemEmail.find_by!(name: "New cookbook version")
.subscribed_users
.pluck(:id)
subscribed_user_ids = SystemEmail
.find_by!(name: "New cookbook version")
.subscribed_users
.pluck(:id)

common_user_ids = active_user_ids & subscribed_user_ids
return if common_user_ids.blank?

emailable_cookbook_followers = cookbook_version.
cookbook.
cookbook_followers.
joins(:user).
where(users: { id: common_user_ids })
emailable_cookbook_followers = cookbook_version
.cookbook
.cookbook_followers
.joins(:user)
.where(users: { id: common_user_ids })

emailable_cookbook_followers.each do |cookbook_follower|
CookbookMailer.follower_notification_email(cookbook_version, cookbook_follower.user).deliver_now
Expand Down
11 changes: 6 additions & 5 deletions src/supermarket/config/initializers/paperclip.rb
Expand Up @@ -5,11 +5,12 @@
# Paperclip has a few remote-fetcher adapters for retrieving attachments from some other place.
# We don't want to use them. Remove these adapters, if they are present in the adapter registry.
remote_adapters = [Paperclip::UriAdapter, Paperclip::HttpUrlProxyAdapter, Paperclip::DataUriAdapter]
Paperclip.io_adapters
.registered_handlers
.delete_if do |_block, handler_class|
remote_adapters.include?(handler_class)
end
Paperclip
.io_adapters
.registered_handlers
.delete_if do |_block, handler_class|
remote_adapters.include?(handler_class)
end

":class/:attachment/:compatible_id/:style/:basename.:extension".tap do |path|
if Supermarket::S3ConfigAudit.use_s3?(ENV)
Expand Down

0 comments on commit 258f0b1

Please sign in to comment.