Apply IndentationConsistency rubocop rule

This commit is contained in:
Javi Martín
2019-06-18 02:34:40 +02:00
parent e252d82cdb
commit 47b2c42a1d
36 changed files with 425 additions and 425 deletions

View File

@@ -17,13 +17,13 @@ class Admin::BudgetPhasesController < Admin::BaseController
private private
def load_phase def load_phase
@phase = Budget::Phase.find(params[:id]) @phase = Budget::Phase.find(params[:id])
end end
def budget_phase_params def budget_phase_params
valid_attributes = [:starts_at, :ends_at, :enabled] valid_attributes = [:starts_at, :ends_at, :enabled]
params.require(:budget_phase).permit(*valid_attributes, translation_params(Budget::Phase)) params.require(:budget_phase).permit(*valid_attributes, translation_params(Budget::Phase))
end end
end end

View File

@@ -13,8 +13,8 @@ class Admin::DebatesController < Admin::BaseController
private private
def resource_model def resource_model
Debate Debate
end end
end end

View File

@@ -12,7 +12,7 @@ class Admin::EmailsDownloadController < Admin::BaseController
private private
def users_segment_emails_csv(users_segment) def users_segment_emails_csv(users_segment)
UserSegments.user_segment_emails(users_segment).join(",") UserSegments.user_segment_emails(users_segment).join(",")
end end
end end

View File

@@ -9,20 +9,20 @@ class Admin::HomepageController < Admin::BaseController
private private
def load_header def load_header
@header = ::Widget::Card.header @header = ::Widget::Card.header
end end
def load_recommendations def load_recommendations
@recommendations = Setting.where(key: "feature.user.recommendations").first @recommendations = Setting.where(key: "feature.user.recommendations").first
end end
def load_cards def load_cards
@cards = ::Widget::Card.body @cards = ::Widget::Card.body
end end
def load_feeds def load_feeds
@feeds = Widget::Feed.order("created_at") @feeds = Widget::Feed.order("created_at")
end end
end end

View File

@@ -41,11 +41,11 @@ class Admin::MilestoneStatusesController < Admin::BaseController
private private
def load_status def load_status
@status = Milestone::Status.find(params[:id]) @status = Milestone::Status.find(params[:id])
end end
def status_params def status_params
params.require(:milestone_status).permit([:name, :description]) params.require(:milestone_status).permit([:name, :description])
end end
end end

View File

@@ -13,27 +13,27 @@ class CommunitiesController < ApplicationController
private private
def set_order def set_order
@order = valid_order? ? params[:order] : "newest" @order = valid_order? ? params[:order] : "newest"
end end
def set_community def set_community
@community = Community.find(params[:id]) @community = Community.find(params[:id])
end end
def load_topics def load_topics
@topics = @community.topics.send("sort_by_#{@order}").page(params[:page]) @topics = @community.topics.send("sort_by_#{@order}").page(params[:page])
end end
def load_participants def load_participants
@participants = @community.participants @participants = @community.participants
end end
def valid_order? def valid_order?
params[:order].present? && TOPIC_ORDERS.include?(params[:order]) params[:order].present? && TOPIC_ORDERS.include?(params[:order])
end end
def communitable_exists? def communitable_exists?
@community.proposal.present? || @community.investment.present? @community.proposal.present? || @community.investment.present?
end end
end end

View File

@@ -39,10 +39,10 @@ class DirectUploadsController < ApplicationController
private private
def direct_upload_params def direct_upload_params
params.require(:direct_upload) params.require(:direct_upload)
.permit(:resource, :resource_type, :resource_id, :resource_relation, .permit(:resource, :resource_type, :resource_id, :resource_relation,
:attachment, :cached_attachment, attachment_attributes: []) :attachment, :cached_attachment, attachment_attributes: [])
end end
end end

View File

@@ -17,12 +17,12 @@ class FollowsController < ApplicationController
private private
def find_followable def find_followable
params[:followable_type].constantize.find(params[:followable_id]) params[:followable_type].constantize.find(params[:followable_id])
end end
def followable_translation_key(followable) def followable_translation_key(followable)
followable.class.name.parameterize(separator: "_") followable.class.name.parameterize(separator: "_")
end end
end end

View File

@@ -10,14 +10,14 @@ class InstallationController < ApplicationController
private private
def consul_installation_details def consul_installation_details
{ {
release: "1.0.0" release: "1.0.0"
}.merge(features: settings_feature_flags) }.merge(features: settings_feature_flags)
end end
def settings_feature_flags def settings_feature_flags
Setting.where("key LIKE 'feature.%'").each_with_object({}) { |x, n| n[x.key.remove("feature.")] = x.value } Setting.where("key LIKE 'feature.%'").each_with_object({}) { |x, n| n[x.key.remove("feature.")] = x.value }
end end
end end

View File

@@ -32,39 +32,39 @@ class Officing::BallotSheetsController < Officing::BaseController
private private
def namespace def namespace
"officing" "officing"
end end
def load_poll def load_poll
@poll = Poll.find(params[:poll_id]) @poll = Poll.find(params[:poll_id])
end end
def load_ballot_sheets def load_ballot_sheets
@ballot_sheets = Poll::BallotSheet.where(poll: @poll) @ballot_sheets = Poll::BallotSheet.where(poll: @poll)
end end
def load_ballot_sheet def load_ballot_sheet
@ballot_sheet = Poll::BallotSheet.find(params[:id]) @ballot_sheet = Poll::BallotSheet.find(params[:id])
end end
def load_officer_assignments def load_officer_assignments
@officer_assignments = ::Poll::OfficerAssignment. @officer_assignments = ::Poll::OfficerAssignment.
includes(booth_assignment: [:booth]). includes(booth_assignment: [:booth]).
joins(:booth_assignment). joins(:booth_assignment).
final. final.
where(id: current_user.poll_officer.officer_assignment_ids). where(id: current_user.poll_officer.officer_assignment_ids).
where("poll_booth_assignments.poll_id = ?", @poll.id). where("poll_booth_assignments.poll_id = ?", @poll.id).
where(date: Date.current) where(date: Date.current)
end end
def load_officer_assignment def load_officer_assignment
@officer_assignment = current_user.poll_officer.officer_assignments.final @officer_assignment = current_user.poll_officer.officer_assignments.final
.find_by(id: ballot_sheet_params[:officer_assignment_id]) .find_by(id: ballot_sheet_params[:officer_assignment_id])
end end
def ballot_sheet_params def ballot_sheet_params
params.permit(:data, :poll_id, :officer_assignment_id) params.permit(:data, :poll_id, :officer_assignment_id)
end end
end end

View File

@@ -13,12 +13,12 @@ class Officing::BoothController < Officing::BaseController
private private
def booth_params def booth_params
params.require(:booth).permit(:id) params.require(:booth).permit(:id)
end end
def set_booth(booth) def set_booth(booth)
session[:booth_id] = booth.id session[:booth_id] = booth.id
end end
end end

View File

@@ -30,32 +30,32 @@ class RelatedContentsController < ApplicationController
private private
def score(action) def score(action)
@related = RelatedContent.find params[:id] @related = RelatedContent.find params[:id]
@related.send("score_#{action}", current_user) @related.send("score_#{action}", current_user)
render template: "relationable/_refresh_score_actions" render template: "relationable/_refresh_score_actions"
end end
def valid_url? def valid_url?
params[:url].start_with?(Setting["url"]) params[:url].start_with?(Setting["url"])
end end
def relationable_object def relationable_object
@relationable = params[:relationable_klass].singularize.camelize.constantize.find_by(id: params[:relationable_id]) @relationable = params[:relationable_klass].singularize.camelize.constantize.find_by(id: params[:relationable_id])
end end
def related_object def related_object
if valid_url? if valid_url?
url = params[:url] url = params[:url]
related_klass = url.scan(/\/(#{RelatedContent::RELATIONABLE_MODELS.join("|")})\//) related_klass = url.scan(/\/(#{RelatedContent::RELATIONABLE_MODELS.join("|")})\//)
.flatten.map { |i| i.to_s.singularize.camelize }.join("::") .flatten.map { |i| i.to_s.singularize.camelize }.join("::")
related_id = url.match(/\/(\d+)(?!.*\/\d)/)[1] related_id = url.match(/\/(\d+)(?!.*\/\d)/)[1]
@related = related_klass.singularize.camelize.constantize.find_by(id: related_id) @related = related_klass.singularize.camelize.constantize.find_by(id: related_id)
end
rescue
nil
end end
rescue
nil
end
end end

View File

@@ -31,15 +31,15 @@ class SandboxController < ApplicationController
private private
def set_layout def set_layout
if params[:template] && params[:template].split("_").first == "admin" if params[:template] && params[:template].split("_").first == "admin"
"admin" "admin"
else else
"application" "application"
end
end end
end
def namespace def namespace
"admin" "admin"
end end
end end

View File

@@ -46,15 +46,15 @@ class TopicsController < ApplicationController
private private
def topic_params def topic_params
params.require(:topic).permit(:title, :description) params.require(:topic).permit(:title, :description)
end end
def load_community def load_community
@community = Community.find(params[:community_id]) @community = Community.find(params[:community_id])
end end
def load_topic def load_topic
@topic = Topic.find(params[:id]) @topic = Topic.find(params[:id])
end end
end end

View File

@@ -33,9 +33,9 @@ class WelcomeController < ApplicationController
private private
def set_user_recommendations def set_user_recommendations
@recommended_debates = Debate.recommendations(current_user).sort_by_recommendations.limit(3) @recommended_debates = Debate.recommendations(current_user).sort_by_recommendations.limit(3)
@recommended_proposals = Proposal.recommendations(current_user).sort_by_recommendations.limit(3) @recommended_proposals = Proposal.recommendations(current_user).sort_by_recommendations.limit(3)
end end
end end

View File

@@ -10,20 +10,20 @@ module FlagsHelper
private private
def flagged?(flaggable) def flagged?(flaggable)
if flaggable.is_a? Comment if flaggable.is_a? Comment
@comment_flags[flaggable.id] unless flaggable.commentable_type == "Poll" @comment_flags[flaggable.id] unless flaggable.commentable_type == "Poll"
else else
Flag.flagged?(current_user, flaggable) Flag.flagged?(current_user, flaggable)
end
end end
end
def own_flaggable?(flaggable) def own_flaggable?(flaggable)
if flaggable.is_a? Comment if flaggable.is_a? Comment
flaggable.user_id == current_user.id flaggable.user_id == current_user.id
else else
flaggable.author_id == current_user.id flaggable.author_id == current_user.id
end
end end
end
end end

View File

@@ -47,24 +47,24 @@ module MapLocationsHelper
private private
def prepare_map_settings(map_location, editable, parent_class, investments_coordinates=nil) def prepare_map_settings(map_location, editable, parent_class, investments_coordinates=nil)
options = { options = {
map: "", map: "",
map_center_latitude: map_location_latitude(map_location), map_center_latitude: map_location_latitude(map_location),
map_center_longitude: map_location_longitude(map_location), map_center_longitude: map_location_longitude(map_location),
map_zoom: map_location_zoom(map_location), map_zoom: map_location_zoom(map_location),
map_tiles_provider: Rails.application.secrets.map_tiles_provider, map_tiles_provider: Rails.application.secrets.map_tiles_provider,
map_tiles_provider_attribution: Rails.application.secrets.map_tiles_provider_attribution, map_tiles_provider_attribution: Rails.application.secrets.map_tiles_provider_attribution,
marker_editable: editable, marker_editable: editable,
marker_remove_selector: "##{map_location_remove_marker_link_id(map_location)}", marker_remove_selector: "##{map_location_remove_marker_link_id(map_location)}",
latitude_input_selector: "##{map_location_input_id(parent_class, "latitude")}", latitude_input_selector: "##{map_location_input_id(parent_class, "latitude")}",
longitude_input_selector: "##{map_location_input_id(parent_class, "longitude")}", longitude_input_selector: "##{map_location_input_id(parent_class, "longitude")}",
zoom_input_selector: "##{map_location_input_id(parent_class, "zoom")}", zoom_input_selector: "##{map_location_input_id(parent_class, "zoom")}",
marker_investments_coordinates: investments_coordinates marker_investments_coordinates: investments_coordinates
} }
options[:marker_latitude] = map_location.latitude if map_location.latitude.present? options[:marker_latitude] = map_location.latitude if map_location.latitude.present?
options[:marker_longitude] = map_location.longitude if map_location.longitude.present? options[:marker_longitude] = map_location.longitude if map_location.longitude.present?
options options
end end
end end

View File

@@ -37,7 +37,7 @@ module ShiftsHelper
private private
def officer_shifts(task_id, booth) def officer_shifts(task_id, booth)
@officer.shifts.where(task: task_id, booth: booth).map(&:date) @officer.shifts.where(task: task_id, booth: booth).map(&:date)
end end
end end

View File

@@ -5,9 +5,9 @@ class DeviseMailer < Devise::Mailer
protected protected
def devise_mail(record, action, opts = {}) def devise_mail(record, action, opts = {})
I18n.with_locale record.locale do I18n.with_locale record.locale do
super(record, action, opts) super(record, action, opts)
end
end end
end
end end

View File

@@ -129,16 +129,16 @@ class Mailer < ApplicationMailer
private private
def with_user(user, &block) def with_user(user, &block)
I18n.with_locale(user.locale) do I18n.with_locale(user.locale) do
yield yield
end
end end
end
def prevent_delivery_to_users_without_email def prevent_delivery_to_users_without_email
if @email_to.blank? if @email_to.blank?
mail.perform_deliveries = false mail.perform_deliveries = false
end
end end
end
end end

View File

@@ -35,14 +35,14 @@ class AdminNotification < ApplicationRecord
private private
def validate_segment_recipient def validate_segment_recipient
errors.add(:segment_recipient, :invalid) unless valid_segment_recipient? errors.add(:segment_recipient, :invalid) unless valid_segment_recipient?
end end
def complete_link_url def complete_link_url
return unless link.present? return unless link.present?
unless self.link[/\Ahttp:\/\//] || self.link[/\Ahttps:\/\//] unless self.link[/\Ahttp:\/\//] || self.link[/\Ahttps:\/\//]
self.link = "http://#{self.link}" self.link = "http://#{self.link}"
end
end end
end
end end

View File

@@ -32,17 +32,17 @@ module Ahoy
private private
def collections def collections
@collections ||= [] @collections ||= []
end end
def shared_keys def shared_keys
@shared_keys ||= [] @shared_keys ||= []
end end
def add_key(key) def add_key(key)
shared_keys.push(key) unless shared_keys.include? key shared_keys.push(key) unless shared_keys.include? key
end end
end end

View File

@@ -205,28 +205,28 @@ class Budget < ApplicationRecord
private private
def sanitize_descriptions def sanitize_descriptions
s = WYSIWYGSanitizer.new s = WYSIWYGSanitizer.new
Budget::Phase::PHASE_KINDS.each do |phase| Budget::Phase::PHASE_KINDS.each do |phase|
sanitized = s.sanitize(send("description_#{phase}")) sanitized = s.sanitize(send("description_#{phase}"))
send("description_#{phase}=", sanitized) send("description_#{phase}=", sanitized)
end
end end
end
def generate_phases def generate_phases
Budget::Phase::PHASE_KINDS.each do |phase| Budget::Phase::PHASE_KINDS.each do |phase|
Budget::Phase.create( Budget::Phase.create(
budget: self, budget: self,
kind: phase, kind: phase,
prev_phase: phases&.last, prev_phase: phases&.last,
starts_at: phases&.last&.ends_at || Date.current, starts_at: phases&.last&.ends_at || Date.current,
ends_at: (phases&.last&.ends_at || Date.current) + 1.month ends_at: (phases&.last&.ends_at || Date.current) + 1.month
) )
end
end end
end
def generate_slug? def generate_slug?
slug.nil? || drafting? slug.nil? || drafting?
end end
end end

View File

@@ -36,8 +36,8 @@ class Budget
private private
def generate_slug? def generate_slug?
slug.nil? || budget.drafting? slug.nil? || budget.drafting?
end end
end end
end end

View File

@@ -56,8 +56,8 @@ class Budget
private private
def generate_slug? def generate_slug?
slug.nil? || budget.drafting? slug.nil? || budget.drafting?
end end
end end
end end

View File

@@ -14,54 +14,54 @@ class Budget::Investment::Exporter
private private
def headers def headers
[ [
I18n.t("admin.budget_investments.index.list.id"), I18n.t("admin.budget_investments.index.list.id"),
I18n.t("admin.budget_investments.index.list.title"), I18n.t("admin.budget_investments.index.list.title"),
I18n.t("admin.budget_investments.index.list.supports"), I18n.t("admin.budget_investments.index.list.supports"),
I18n.t("admin.budget_investments.index.list.admin"), I18n.t("admin.budget_investments.index.list.admin"),
I18n.t("admin.budget_investments.index.list.valuator"), I18n.t("admin.budget_investments.index.list.valuator"),
I18n.t("admin.budget_investments.index.list.valuation_group"), I18n.t("admin.budget_investments.index.list.valuation_group"),
I18n.t("admin.budget_investments.index.list.geozone"), I18n.t("admin.budget_investments.index.list.geozone"),
I18n.t("admin.budget_investments.index.list.feasibility"), I18n.t("admin.budget_investments.index.list.feasibility"),
I18n.t("admin.budget_investments.index.list.valuation_finished"), I18n.t("admin.budget_investments.index.list.valuation_finished"),
I18n.t("admin.budget_investments.index.list.selected"), I18n.t("admin.budget_investments.index.list.selected"),
I18n.t("admin.budget_investments.index.list.visible_to_valuators"), I18n.t("admin.budget_investments.index.list.visible_to_valuators"),
I18n.t("admin.budget_investments.index.list.author_username") I18n.t("admin.budget_investments.index.list.author_username")
] ]
end
def csv_values(investment)
[
investment.id.to_s,
investment.title,
investment.total_votes.to_s,
admin(investment),
investment.assigned_valuators || "-",
investment.assigned_valuation_groups || "-",
investment.heading.name,
price(investment),
investment.valuation_finished? ? I18n.t("shared.yes") : I18n.t("shared.no"),
investment.selected? ? I18n.t("shared.yes") : I18n.t("shared.no"),
investment.visible_to_valuators? ? I18n.t("shared.yes") : I18n.t("shared.no"),
investment.author.username
]
end
def admin(investment)
if investment.administrator.present?
investment.administrator.name
else
I18n.t("admin.budget_investments.index.no_admin_assigned")
end end
end
def price(investment) def csv_values(investment)
price_string = "admin.budget_investments.index.feasibility.#{investment.feasibility}" [
if investment.feasible? investment.id.to_s,
"#{I18n.t(price_string)} (#{investment.formatted_price})" investment.title,
else investment.total_votes.to_s,
I18n.t(price_string) admin(investment),
investment.assigned_valuators || "-",
investment.assigned_valuation_groups || "-",
investment.heading.name,
price(investment),
investment.valuation_finished? ? I18n.t("shared.yes") : I18n.t("shared.no"),
investment.selected? ? I18n.t("shared.yes") : I18n.t("shared.no"),
investment.visible_to_valuators? ? I18n.t("shared.yes") : I18n.t("shared.no"),
investment.author.username
]
end
def admin(investment)
if investment.administrator.present?
investment.administrator.name
else
I18n.t("admin.budget_investments.index.no_admin_assigned")
end
end
def price(investment)
price_string = "admin.budget_investments.index.feasibility.#{investment.feasibility}"
if investment.feasible?
"#{I18n.t(price_string)} (#{investment.formatted_price})"
else
I18n.t(price_string)
end
end end
end
end end

View File

@@ -11,25 +11,25 @@ class CommentNotifier
private private
def send_comment_email def send_comment_email
unless @comment.commentable.is_a?(Legislation::Annotation) unless @comment.commentable.is_a?(Legislation::Annotation)
Mailer.comment(@comment).deliver_later if email_on_comment? Mailer.comment(@comment).deliver_later if email_on_comment?
end
end end
end
def send_reply_email def send_reply_email
Mailer.reply(@comment).deliver_later if email_on_comment_reply? Mailer.reply(@comment).deliver_later if email_on_comment_reply?
end end
def email_on_comment? def email_on_comment?
commentable_author = @comment.commentable.author commentable_author = @comment.commentable.author
commentable_author != @author && commentable_author.email_on_comment? commentable_author != @author && commentable_author.email_on_comment?
end end
def email_on_comment_reply? def email_on_comment_reply?
return false unless @comment.reply? return false unless @comment.reply?
parent_author = @comment.parent.author parent_author = @comment.parent.author
parent_author != @author && parent_author.email_on_comment_reply? parent_author != @author && parent_author.email_on_comment_reply?
end end
end end

View File

@@ -44,18 +44,18 @@ class Community < ApplicationRecord
private private
def users_who_commented def users_who_commented
topics_ids = topics.pluck(:id) topics_ids = topics.pluck(:id)
query = "comments.commentable_id IN (?)and comments.commentable_type = 'Topic'" query = "comments.commentable_id IN (?)and comments.commentable_type = 'Topic'"
User.by_comments(query, topics_ids) User.by_comments(query, topics_ids)
end end
def users_who_topics_author def users_who_topics_author
author_ids = topics.pluck(:author_id) author_ids = topics.pluck(:author_id)
User.by_authors(author_ids) User.by_authors(author_ids)
end end
def author_from_community def author_from_community
from_proposal? ? User.where(id: proposal&.author_id) : User.where(id: investment&.author_id) from_proposal? ? User.where(id: proposal&.author_id) : User.where(id: investment&.author_id)
end end
end end

View File

@@ -12,23 +12,23 @@ module SearchCache
private private
def searchable_values_sql def searchable_values_sql
searchable_values searchable_values
.select{ |k, _| k.present? } .select{ |k, _| k.present? }
.collect{ |value, weight| set_tsvector(value, weight) } .collect{ |value, weight| set_tsvector(value, weight) }
.join(" || ") .join(" || ")
end end
def set_tsvector(value, weight) def set_tsvector(value, weight)
"setweight(to_tsvector('spanish', unaccent(coalesce(#{quote(strip_html(value))}, ''))), #{quote(weight)})" "setweight(to_tsvector('spanish', unaccent(coalesce(#{quote(strip_html(value))}, ''))), #{quote(weight)})"
end end
def quote(value) def quote(value)
ActiveRecord::Base.connection.quote(value) ActiveRecord::Base.connection.quote(value)
end end
def strip_html(value) def strip_html(value)
ActionController::Base.helpers.sanitize(value, tags: []) ActionController::Base.helpers.sanitize(value, tags: [])
end end
end end

View File

@@ -6,6 +6,42 @@ module Statisticable
attr_reader :resource attr_reader :resource
end end
class_methods do
def stats_methods
base_stats_methods + gender_methods + age_methods + geozone_methods
end
def base_stats_methods
%i[total_participants participations] + participation_check_methods
end
def participation_check_methods
PARTICIPATIONS.map { |participation| :"#{participation}?" }
end
def gender_methods
%i[total_male_participants total_female_participants male_percentage female_percentage]
end
def age_methods
[:participants_by_age]
end
def geozone_methods
%i[participants_by_geozone total_no_demographic_data]
end
def stats_cache(*method_names)
method_names.each do |method_name|
alias_method :"raw_#{method_name}", method_name
define_method method_name do
stats_cache(method_name) { send(:"raw_#{method_name}") }
end
end
end
end
def initialize(resource) def initialize(resource)
@resource = resource @resource = resource
end end
@@ -150,40 +186,4 @@ module Statisticable
I18n.t("stats.age_range", start: start, finish: finish) I18n.t("stats.age_range", start: start, finish: finish)
end end
end end
class_methods do
def stats_methods
base_stats_methods + gender_methods + age_methods + geozone_methods
end
def base_stats_methods
%i[total_participants participations] + participation_check_methods
end
def participation_check_methods
PARTICIPATIONS.map { |participation| :"#{participation}?" }
end
def gender_methods
%i[total_male_participants total_female_participants male_percentage female_percentage]
end
def age_methods
[:participants_by_age]
end
def geozone_methods
%i[participants_by_geozone total_no_demographic_data]
end
def stats_cache(*method_names)
method_names.each do |method_name|
alias_method :"raw_#{method_name}", method_name
define_method method_name do
stats_cache(method_name) { send(:"raw_#{method_name}") }
end
end
end
end
end end

View File

@@ -47,20 +47,20 @@ class DirectUpload
private private
def parent_resource_attachment_validations def parent_resource_attachment_validations
@relation.valid? @relation.valid?
if @relation.errors.key? :attachment if @relation.errors.key? :attachment
errors.add(:attachment, @relation.errors.full_messages_for(:attachment)) errors.add(:attachment, @relation.errors.full_messages_for(:attachment))
end
end end
end
def relation_attributtes def relation_attributtes
{ {
attachment: @attachment, attachment: @attachment,
cached_attachment: @cached_attachment, cached_attachment: @cached_attachment,
user: @user user: @user
} }
end end
end end

View File

@@ -55,16 +55,16 @@ class Newsletter < ApplicationRecord
private private
def validate_segment_recipient def validate_segment_recipient
errors.add(:segment_recipient, :invalid) unless valid_segment_recipient? errors.add(:segment_recipient, :invalid) unless valid_segment_recipient?
end end
def valid_email?(email) def valid_email?(email)
email.match(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i) email.match(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i)
end end
def log_delivery(recipient_email) def log_delivery(recipient_email)
user = User.where(email: recipient_email).first user = User.where(email: recipient_email).first
Activity.log(user, :email, self) Activity.log(user, :email, self)
end end
end end

View File

@@ -82,16 +82,16 @@ class Notification < ApplicationRecord
private private
def self.batch_size def self.batch_size
10000 10000
end end
def self.batch_interval def self.batch_interval
20.minutes 20.minutes
end end
def self.first_batch_run_at def self.first_batch_run_at
Time.current Time.current
end end
end end

View File

@@ -56,8 +56,8 @@ class ProposalNotification < ApplicationRecord
private private
def set_author def set_author
self.update(author_id: self.proposal.author_id) if self.proposal self.update(author_id: self.proposal.author_id) if self.proposal
end end
end end

View File

@@ -36,28 +36,28 @@ class RelatedContent < ApplicationRecord
private private
def create_opposite_related_content def create_opposite_related_content
related_content = RelatedContent.create!(opposite_related_content: self, parent_relationable: child_relationable, related_content = RelatedContent.create!(opposite_related_content: self, parent_relationable: child_relationable,
child_relationable: parent_relationable, author: author) child_relationable: parent_relationable, author: author)
self.opposite_related_content = related_content self.opposite_related_content = related_content
end end
def score(value, user) def score(value, user)
score_with_opposite(value, user) score_with_opposite(value, user)
hide_with_opposite if (related_content_scores.sum(:value) / related_content_scores_count) < RELATED_CONTENT_SCORE_THRESHOLD hide_with_opposite if (related_content_scores.sum(:value) / related_content_scores_count) < RELATED_CONTENT_SCORE_THRESHOLD
end end
def hide_with_opposite def hide_with_opposite
hide hide
opposite_related_content.hide opposite_related_content.hide
end end
def create_author_score def create_author_score
score_positive(author) score_positive(author)
end end
def score_with_opposite(value, user) def score_with_opposite(value, user)
RelatedContentScore.create(user: user, related_content: self, value: value) RelatedContentScore.create(user: user, related_content: self, value: value)
RelatedContentScore.create(user: user, related_content: opposite_related_content, value: value) RelatedContentScore.create(user: user, related_content: opposite_related_content, value: value)
end end
end end

View File

@@ -60,11 +60,11 @@ class UserSegments
private private
def self.current_budget_investments def self.current_budget_investments
Budget.current.investments Budget.current.investments
end end
def self.author_ids(author_ids) def self.author_ids(author_ids)
all_users.where(id: author_ids) all_users.where(id: author_ids)
end end
end end