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
def load_phase
@phase = Budget::Phase.find(params[:id])
end
def load_phase
@phase = Budget::Phase.find(params[:id])
end
def budget_phase_params
valid_attributes = [:starts_at, :ends_at, :enabled]
params.require(:budget_phase).permit(*valid_attributes, translation_params(Budget::Phase))
end
def budget_phase_params
valid_attributes = [:starts_at, :ends_at, :enabled]
params.require(:budget_phase).permit(*valid_attributes, translation_params(Budget::Phase))
end
end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -14,54 +14,54 @@ class Budget::Investment::Exporter
private
def headers
[
I18n.t("admin.budget_investments.index.list.id"),
I18n.t("admin.budget_investments.index.list.title"),
I18n.t("admin.budget_investments.index.list.supports"),
I18n.t("admin.budget_investments.index.list.admin"),
I18n.t("admin.budget_investments.index.list.valuator"),
I18n.t("admin.budget_investments.index.list.valuation_group"),
I18n.t("admin.budget_investments.index.list.geozone"),
I18n.t("admin.budget_investments.index.list.feasibility"),
I18n.t("admin.budget_investments.index.list.valuation_finished"),
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.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")
def headers
[
I18n.t("admin.budget_investments.index.list.id"),
I18n.t("admin.budget_investments.index.list.title"),
I18n.t("admin.budget_investments.index.list.supports"),
I18n.t("admin.budget_investments.index.list.admin"),
I18n.t("admin.budget_investments.index.list.valuator"),
I18n.t("admin.budget_investments.index.list.valuation_group"),
I18n.t("admin.budget_investments.index.list.geozone"),
I18n.t("admin.budget_investments.index.list.feasibility"),
I18n.t("admin.budget_investments.index.list.valuation_finished"),
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.author_username")
]
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)
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
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

View File

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

View File

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

View File

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

View File

@@ -6,6 +6,42 @@ module Statisticable
attr_reader :resource
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)
@resource = resource
end
@@ -150,40 +186,4 @@ module Statisticable
I18n.t("stats.age_range", start: start, finish: finish)
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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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