This rule was introduced in RuboCop 1.76.0 to ensure methods ending in '?' return boolean. This commit applies suggested renames and code cleanup: - Renames 'is_active?' to 'active_class' since it returns a string - Renames 'parsed_value' to 'in_favor?' and 'is_request_active' to end with '?' for boolean semantics - Skips false positives like 'save', 'auto_labels' or 'save_requiring_finish_signup', which are not predicate methods.
49 lines
948 B
Ruby
49 lines
948 B
Ruby
class Shared::VoteButtonComponent < ApplicationComponent
|
|
attr_reader :votable, :value, :options
|
|
use_helpers :current_user, :can?
|
|
|
|
def initialize(votable, value:, **options)
|
|
@votable = votable
|
|
@value = value
|
|
@options = options
|
|
end
|
|
|
|
private
|
|
|
|
def path
|
|
if already_voted?
|
|
polymorphic_path(vote)
|
|
else
|
|
polymorphic_path(vote, value: value)
|
|
end
|
|
end
|
|
|
|
def default_options
|
|
if already_voted?
|
|
{
|
|
"aria-pressed": true,
|
|
method: :delete,
|
|
remote: can?(:destroy, vote)
|
|
}
|
|
else
|
|
{
|
|
"aria-pressed": false,
|
|
method: :post,
|
|
remote: can?(:create, vote)
|
|
}
|
|
end
|
|
end
|
|
|
|
def vote
|
|
@vote ||= Vote.find_or_initialize_by(votable: votable, voter: current_user, vote_flag: in_favor?)
|
|
end
|
|
|
|
def already_voted?
|
|
vote.persisted?
|
|
end
|
|
|
|
def in_favor?
|
|
value == "yes"
|
|
end
|
|
end
|