Skip to content

Commit

Permalink
Move watcher helper inside the module
Browse files Browse the repository at this point in the history
HDinger committed Nov 26, 2024
1 parent a180964 commit a7c0b0a
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions app/helpers/watchers_helper.rb
Original file line number Diff line number Diff line change
@@ -51,30 +51,30 @@ def watcher_link(object, user, options = { replace: ".watcher_link", class: "wat
link_to(content_tag(:i, "", class: watched ? "button--icon icon-watched" : " button--icon icon-unwatched") + " " +
content_tag(:span, label, class: "button--text"), path, html_options.merge(method:))
end

Check notice on line 53 in app/helpers/watchers_helper.rb

GitHub Actions / rubocop

[rubocop] app/helpers/watchers_helper.rb#L33-L53 <Metrics/AbcSize>

Assignment Branch Condition size for watcher_link is too high. [<7, 24, 8> 26.25/17]
Raw output
app/helpers/watchers_helper.rb:33:3: C: Metrics/AbcSize: Assignment Branch Condition size for watcher_link is too high. [<7, 24, 8> 26.25/17]

Check notice on line 53 in app/helpers/watchers_helper.rb

GitHub Actions / rubocop

[rubocop] app/helpers/watchers_helper.rb#L33-L53 <Metrics/PerceivedComplexity>

Perceived complexity for watcher_link is too high. [9/8]
Raw output
app/helpers/watchers_helper.rb:33:3: C: Metrics/PerceivedComplexity: Perceived complexity for watcher_link is too high. [9/8]
end

def watcher_button_arguments(object, user)
return nil unless user&.logged? && object.respond_to?(:watched_by?)
def watcher_button_arguments(object, user)
return nil unless user&.logged? && object.respond_to?(:watched_by?)

watched = object.watched_by?(user)
watched = object.watched_by?(user)

path = send(:"#{(watched ? 'unwatch' : 'watch')}_path",
object_type: object.class.to_s.underscore.pluralize,
object_id: object.id)
path = send(:"#{(watched ? 'unwatch' : 'watch')}_path",
object_type: object.class.to_s.underscore.pluralize,
object_id: object.id)

method = watched ? :delete : :post
method = watched ? :delete : :post

label = watched ? I18n.t(:button_unwatch) : I18n.t(:button_watch)
label = watched ? I18n.t(:button_unwatch) : I18n.t(:button_watch)

{
tag: :a,
href: path,
scheme: :default,
aria: { label: label },
data: {
method:
},
mobile_icon: watched ? "eye-closed" : "eye",
mobile_label: label
}
{
tag: :a,
href: path,
scheme: :default,
aria: { label: label },
data: {
method:
},
mobile_icon: watched ? "eye-closed" : "eye",
mobile_label: label
}
end
end

0 comments on commit a7c0b0a

Please sign in to comment.