This rule was added in rubocop 1.44.0. It's useful to avoid accidental `unless !condition` clauses. Note we aren't replacing `unless zero?` with `if nonzero?` because we never use `nonzero?`; using it sounds like `if !zero?`. Replacing `unless any?` with `if none?` is only consistent if we also replace `unless present?` with `if blank?`, so we're also adding this case. For consistency, we're also replacing `unless blank?` with `if present?`. We're also simplifying code dealing with `> 0` conditions in order to make the code (hopefully) easier to understand. Also for consistency, we're enabling the `Style/InverseMethods` rule, which follows a similar idea.
31 lines
929 B
Ruby
31 lines
929 B
Ruby
class Admin::Api::StatsController < Admin::Api::BaseController
|
|
def show
|
|
if params[:event].blank? &&
|
|
params[:visits].blank? &&
|
|
params[:budget_investments].blank? &&
|
|
params[:user_supported_budgets].blank?
|
|
return render json: {}, status: :bad_request
|
|
end
|
|
|
|
ds = Ahoy::DataSource.new
|
|
|
|
if params[:event].present?
|
|
ds.add params[:event].titleize, Ahoy::Event.where(name: params[:event]).group_by_day(:time).count
|
|
end
|
|
|
|
if params[:visits].present?
|
|
ds.add "Visits", Visit.group_by_day(:started_at).count
|
|
end
|
|
|
|
if params[:budget_investments].present?
|
|
ds.add "Budget Investments", Budget::Investment.group_by_day(:created_at).count
|
|
end
|
|
|
|
if params[:user_supported_budgets].present?
|
|
ds.add "User supported budgets",
|
|
Vote.where(votable_type: "Budget::Investment").group_by_day(:updated_at).count
|
|
end
|
|
render json: ds.build
|
|
end
|
|
end
|