Commit d318efce authored by hellekin's avatar hellekin

Make rubocop happy

parent 851dcb28
......@@ -19,6 +19,7 @@ class Api::V0::AgentsController < ApplicationController
private
def model_types
%w(collections editors leaders maintainers observers origins roles sections taxonomies users).freeze
%w(collections editors leaders maintainers observers
origins roles sections taxonomies users).freeze
end
end
# frozen_string_literal: true
module EmailHelper
module_function
def hash_email(address)
Digest::SHA256.hexdigest(address.to_s)
end
module_function :hash_email
end
......@@ -17,43 +17,46 @@ class AgentCreator
@agent = nil
end
def self.create(options)
Agent.transaction do
@creator = new(options)
Rails.logger.info "AgentCreator.create(name: #{@creator.name}, email: #{@creator.email}...)"
Rails.logger.info "In transaction with #{@creator.name}, #{@creator.email}"
agent = Agent.i18n.find_or_create_by!(
name: @creator.name,
summary: @creator.summary,
description: @creator.description
)
if agent.id_before_last_save.nil?
# New record: needs email & link
Rails.logger.info "Yes, a new user! #{@creator.inspect} #{agent.inspect}"
email_for!(agent)
link_for!(agent) if @creator.uri.present?
agent.save
class << self
def create(options)
Agent.transaction do
@creator = new(options)
Rails.logger.info \
"AgentCreator.create(name: #{@creator.name}, email: #{@creator.email}...)"
Rails.logger.info "In transaction with #{@creator.name}, #{@creator.email}"
agent = Agent.i18n.find_or_create_by!(
name: @creator.name,
summary: @creator.summary,
description: @creator.description
)
if agent.id_before_last_save.nil?
# New record: needs email & link
Rails.logger.info "Yes, a new user! #{@creator.inspect} #{agent.inspect}"
email_for!(agent)
link_for!(agent) if @creator.uri.present?
agent.save
end
@agent = agent if agent.valid?
end
@agent = agent if agent.valid?
end
end
private
def self.email_for!(agent)
Rails.logger.info "Setting email to #{@creator.email} for #{agent.name}"
email = Email.with_address!(@creator.email)
re = agent.resource_emails.create!(email: email)
re.primary = true
re.validated = @creator.email_validated
re.save
end
private
def self.link_for!(agent)
Rails.logger.info "Setting link to #{@creator.uri} for #{agent.name}"
rl = agent.resource_links.create!(link: Link.with_uri!(@creator.uri))
rl.homepage = true
rl.origin = @creator.uri_is_origin
rl.save
def email_for!(agent)
Rails.logger.info "Setting email to #{@creator.email} for #{agent.name}"
email = Email.with_address!(@creator.email)
re = agent.resource_emails.create!(email: email)
re.primary = true
re.validated = @creator.email_validated
re.save
end
def link_for!(agent)
Rails.logger.info "Setting link to #{@creator.uri} for #{agent.name}"
rl = agent.resource_links.create!(link: Link.with_uri!(@creator.uri))
rl.homepage = true
rl.origin = @creator.uri_is_origin
rl.save
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment