Skip to content

Commit

Permalink
apply rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeta committed Jan 19, 2025
1 parent 25c9b4c commit bbe5f77
Show file tree
Hide file tree
Showing 116 changed files with 1,160 additions and 1,160 deletions.
4 changes: 2 additions & 2 deletions app/models/accept.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class Accept < ApplicationRecord
include EnjuCirculation::EnjuAccept
default_scope { order('accepts.id DESC') }
default_scope { order("accepts.id DESC") }
belongs_to :basket
belongs_to :item, touch: true
belongs_to :librarian, class_name: 'User'
belongs_to :librarian, class_name: "User"

validates :item_id, uniqueness: true # , message: I18n.t('accept.already_accepted')

Expand Down
74 changes: 37 additions & 37 deletions app/models/agent.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class Agent < ApplicationRecord
include EnjuNdl::EnjuAgent

scope :readable_by, lambda{ |user|
scope :readable_by, lambda { |user|
if user
where('required_role_id <= ?', user.try(:user_has_role).try(:role_id))
where("required_role_id <= ?", user.try(:user_has_role).try(:role_id))
else
where('required_role_id <= 1')
where("required_role_id <= 1")
end
}
has_many :creates, dependent: :destroy
Expand All @@ -14,8 +14,8 @@ class Agent < ApplicationRecord
has_many :expressions, through: :realizes
has_many :produces, dependent: :destroy
has_many :manifestations, through: :produces
has_many :children, foreign_key: 'parent_id', class_name: 'AgentRelationship', dependent: :destroy, inverse_of: :parent
has_many :parents, foreign_key: 'child_id', class_name: 'AgentRelationship', dependent: :destroy, inverse_of: :child
has_many :children, foreign_key: "parent_id", class_name: "AgentRelationship", dependent: :destroy, inverse_of: :parent
has_many :parents, foreign_key: "child_id", class_name: "AgentRelationship", dependent: :destroy, inverse_of: :child
has_many :derived_agents, through: :children, source: :child
has_many :original_agents, through: :parents, source: :parent
has_many :picture_files, as: :picture_attachable, dependent: :destroy
Expand All @@ -26,7 +26,7 @@ class Agent < ApplicationRecord
has_many :agent_merges, dependent: :destroy
has_many :agent_merge_lists, through: :agent_merges
belongs_to :agent_type
belongs_to :required_role, class_name: 'Role'
belongs_to :required_role, class_name: "Role"
belongs_to :language
belongs_to :country
has_one :agent_import_result
Expand All @@ -40,17 +40,17 @@ class Agent < ApplicationRecord
before_validation :set_role_and_name, on: :create
before_save :set_date_of_birth, :set_date_of_death
after_save do |agent|
agent.works.map{|work| work.touch && work.index}
agent.expressions.map{|expression| expression.touch && expression.index}
agent.manifestations.map{|manifestation| manifestation.touch && manifestation.index}
agent.items.map{|item| item.touch && item.index}
agent.works.map { |work| work.touch && work.index }
agent.expressions.map { |expression| expression.touch && expression.index }
agent.manifestations.map { |manifestation| manifestation.touch && manifestation.index }
agent.items.map { |item| item.touch && item.index }
Sunspot.commit
end
after_destroy do |agent|
agent.works.map{|work| work.touch && work.index}
agent.expressions.map{|expression| expression.touch && expression.index}
agent.manifestations.map{|manifestation| manifestation.touch && manifestation.index}
agent.items.map{|item| item.touch && item.index}
agent.works.map { |work| work.touch && work.index }
agent.expressions.map { |expression| expression.touch && expression.index }
agent.manifestations.map { |manifestation| manifestation.touch && manifestation.index }
agent.items.map { |item| item.touch && item.index }
Sunspot.commit
end

Expand Down Expand Up @@ -79,22 +79,22 @@ class Agent < ApplicationRecord
paginates_per 10

def set_role_and_name
self.required_role = Role.find_by(name: 'Librarian') if required_role_id.nil?
self.required_role = Role.find_by(name: "Librarian") if required_role_id.nil?
set_full_name
end

def set_full_name
if full_name.blank?
if LibraryGroup.site_config.family_name_first
self.full_name = [last_name, middle_name, first_name].compact.join(" ").to_s.strip
self.full_name = [ last_name, middle_name, first_name ].compact.join(" ").to_s.strip
else
self.full_name = [first_name, last_name, middle_name].compact.join(" ").to_s.strip
self.full_name = [ first_name, last_name, middle_name ].compact.join(" ").to_s.strip
end
end
if full_name_transcription.blank?
self.full_name_transcription = [last_name_transcription, middle_name_transcription, first_name_transcription].join(" ").to_s.strip
self.full_name_transcription = [ last_name_transcription, middle_name_transcription, first_name_transcription ].join(" ").to_s.strip
end
[full_name, full_name_transcription]
[ full_name, full_name_transcription ]
end

def set_date_of_birth
Expand Down Expand Up @@ -145,15 +145,15 @@ def check_birth_date
end
end

#def full_name_generate
# def full_name_generate
# # TODO: 日本人以外は?
# name = []
# name << self.last_name.to_s.strip
# name << self.middle_name.to_s.strip unless self.middle_name.blank?
# name << self.first_name.to_s.strip
# name << self.corporate_name.to_s.strip
# name.join(" ").strip
#end
# end

def full_name_without_space
full_name.gsub(/[\s,]/, "")
Expand All @@ -180,11 +180,11 @@ def name
name << full_name_transcription.to_s.strip
name << full_name_alternative.to_s.strip
name << full_name_without_space
#name << full_name_transcription_without_space
#name << full_name_alternative_without_space
#name << full_name.wakati rescue nil
#name << full_name_transcription.wakati rescue nil
#name << full_name_alternative.wakati rescue nil
# name << full_name_transcription_without_space
# name << full_name_alternative_without_space
# name << full_name.wakati rescue nil
# name << full_name_transcription.wakati rescue nil
# name << full_name_alternative.wakati rescue nil
name
end

Expand Down Expand Up @@ -225,7 +225,7 @@ def owned(item)
def self.import_agents(agent_lists)
agents = []
agent_lists.each do |agent_list|
name_and_role = agent_list[:full_name].split('||')
name_and_role = agent_list[:full_name].split("||")
if agent_list[:ndla_identifier].present?
agent = NdlaRecord.find_by(body: agent_list[:ndla_identifier])&.agent
elsif agent_list[:agent_identifier].present?
Expand All @@ -245,7 +245,7 @@ def self.import_agents(agent_lists)
place: agent_list[:place],
language_id: 1
)
agent.required_role = Role.find_by(name: 'Guest')
agent.required_role = Role.find_by(name: "Guest")
agent.save

if agent_list[:ndla_identifier].present?
Expand All @@ -268,20 +268,20 @@ def self.new_agents(agents_params)
agents = []
Agent.transaction do
agents_params.each do |k, v|
next if v['_destroy'] == '1'
next if v["_destroy"] == "1"

agent = nil

if v['agent_id'].present?
agent = Agent.find(v['agent_id'])
elsif v['id'].present?
agent = Agent.find(v['id'])
if v["agent_id"].present?
agent = Agent.find(v["agent_id"])
elsif v["id"].present?
agent = Agent.find(v["id"])
end

if !agent or agent.full_name != v['full_name']
v.delete('id')
v.delete('agent_id')
v.delete('_destroy')
if !agent or agent.full_name != v["full_name"]
v.delete("id")
v.delete("agent_id")
v.delete("_destroy")
agent = Agent.create(v)
end

Expand Down
94 changes: 47 additions & 47 deletions app/models/agent_import_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class AgentImportFile < ApplicationRecord
initial_state: AgentImportFileStateMachine.initial_state
]
include ImportFile
default_scope { order('agent_import_files.id DESC') }
default_scope { order("agent_import_files.id DESC") }
scope :not_imported, -> { in_state(:pending) }
scope :stucked, -> { in_state(:pending).where('agent_import_files.created_at < ?', 1.hour.ago) }
scope :stucked, -> { in_state(:pending).where("agent_import_files.created_at < ?", 1.hour.ago) }

has_one_attached :attachment
belongs_to :user
Expand All @@ -25,11 +25,11 @@ def state_machine

def import_start
case edit_mode
when 'create'
when "create"
import
when 'update'
when "update"
modify
when 'destroy'
when "destroy"
remove
else
import
Expand All @@ -42,17 +42,17 @@ def import
rows = open_import_file
field = rows.first
row_num = 1
if [field['first_name'], field['last_name'], field['full_name']].reject{|field| field.to_s.strip == ""}.empty?
if [ field["first_name"], field["last_name"], field["full_name"] ].reject { |field| field.to_s.strip == "" }.empty?
raise "You should specify first_name, last_name or full_name in the first line"
end

#rows.shift
# rows.shift

AgentImportResult.create!(agent_import_file_id: id, body: rows.headers.join("\t"))
rows.each do |row|
row_num += 1
import_result = AgentImportResult.create!(agent_import_file_id: id, body: row.fields.join("\t"))
next if row['dummy'].to_s.strip.present?
next if row["dummy"].to_s.strip.present?

agent = Agent.new
agent = set_agent_value(agent, row)
Expand Down Expand Up @@ -94,21 +94,21 @@ def modify

rows.each do |row|
row_num += 1
next if row['dummy'].to_s.strip.present?
next if row["dummy"].to_s.strip.present?

agent = Agent.find_by(id: row['id'])
agent = Agent.find_by(id: row["id"])
next unless agent

agent.full_name = row['full_name'] if row['full_name'].to_s.strip.present?
agent.full_name_transcription = row['full_name_transcription'] if row['full_name_transcription'].to_s.strip.present?
agent.first_name = row['first_name'] if row['first_name'].to_s.strip.present?
agent.first_name_transcription = row['first_name_transcription'] if row['first_name_transcription'].to_s.strip.present?
agent.middle_name = row['middle_name'] if row['middle_name'].to_s.strip.present?
agent.middle_name_transcription = row['middle_name_transcription'] if row['middle_name_transcription'].to_s.strip.present?
agent.last_name = row['last_name'] if row['last_name'].to_s.strip.present?
agent.last_name_transcription = row['last_name_transcription'] if row['last_name_transcription'].to_s.strip.present?
agent.address_1 = row['address_1'] if row['address_1'].to_s.strip.present?
agent.address_2 = row['address_2'] if row['address_2'].to_s.strip.present?
agent.full_name = row["full_name"] if row["full_name"].to_s.strip.present?
agent.full_name_transcription = row["full_name_transcription"] if row["full_name_transcription"].to_s.strip.present?
agent.first_name = row["first_name"] if row["first_name"].to_s.strip.present?
agent.first_name_transcription = row["first_name_transcription"] if row["first_name_transcription"].to_s.strip.present?
agent.middle_name = row["middle_name"] if row["middle_name"].to_s.strip.present?
agent.middle_name_transcription = row["middle_name_transcription"] if row["middle_name_transcription"].to_s.strip.present?
agent.last_name = row["last_name"] if row["last_name"].to_s.strip.present?
agent.last_name_transcription = row["last_name_transcription"] if row["last_name_transcription"].to_s.strip.present?
agent.address_1 = row["address_1"] if row["address_1"].to_s.strip.present?
agent.address_2 = row["address_2"] if row["address_2"].to_s.strip.present?
agent.save!
end
transition_to!(:completed)
Expand All @@ -130,9 +130,9 @@ def remove

rows.each do |row|
row_num += 1
next if row['dummy'].to_s.strip.present?
next if row["dummy"].to_s.strip.present?

agent = Agent.find_by(id: row['id'].to_s.strip)
agent = Agent.find_by(id: row["id"].to_s.strip)
next unless agent

agent.picture_files.destroy_all
Expand Down Expand Up @@ -166,37 +166,37 @@ def open_import_file
end

def set_agent_value(agent, row)
agent.first_name = row['first_name'] if row['first_name']
agent.middle_name = row['middle_name'] if row['middle_name']
agent.last_name = row['last_name'] if row['last_name']
agent.first_name_transcription = row['first_name_transcription'] if row['first_name_transcription']
agent.middle_name_transcription = row['middle_name_transcription'] if row['middle_name_transcription']
agent.last_name_transcription = row['last_name_transcription'] if row['last_name_transcription']

agent.full_name = row['full_name'] if row['full_name']
agent.full_name_transcription = row['full_name_transcription'] if row['full_name_transcription']

agent.address_1 = row['address_1'] if row['address_1']
agent.address_2 = row['address_2'] if row['address_2']
agent.zip_code_1 = row['zip_code_1'] if row['zip_code_1']
agent.zip_code_2 = row['zip_code_2'] if row['zip_code_2']
agent.telephone_number_1 = row['telephone_number_1'] if row['telephone_number_1']
agent.telephone_number_2 = row['telephone_number_2'] if row['telephone_number_2']
agent.fax_number_1 = row['fax_number_1'] if row['fax_number_1']
agent.fax_number_2 = row['fax_number_2'] if row['fax_number_2']
agent.note = row['note'] if row['note']
agent.birth_date = row['birth_date'] if row['birth_date']
agent.death_date = row['death_date'] if row['death_date']
agent.first_name = row["first_name"] if row["first_name"]
agent.middle_name = row["middle_name"] if row["middle_name"]
agent.last_name = row["last_name"] if row["last_name"]
agent.first_name_transcription = row["first_name_transcription"] if row["first_name_transcription"]
agent.middle_name_transcription = row["middle_name_transcription"] if row["middle_name_transcription"]
agent.last_name_transcription = row["last_name_transcription"] if row["last_name_transcription"]

agent.full_name = row["full_name"] if row["full_name"]
agent.full_name_transcription = row["full_name_transcription"] if row["full_name_transcription"]

agent.address_1 = row["address_1"] if row["address_1"]
agent.address_2 = row["address_2"] if row["address_2"]
agent.zip_code_1 = row["zip_code_1"] if row["zip_code_1"]
agent.zip_code_2 = row["zip_code_2"] if row["zip_code_2"]
agent.telephone_number_1 = row["telephone_number_1"] if row["telephone_number_1"]
agent.telephone_number_2 = row["telephone_number_2"] if row["telephone_number_2"]
agent.fax_number_1 = row["fax_number_1"] if row["fax_number_1"]
agent.fax_number_2 = row["fax_number_2"] if row["fax_number_2"]
agent.note = row["note"] if row["note"]
agent.birth_date = row["birth_date"] if row["birth_date"]
agent.death_date = row["death_date"] if row["death_date"]

# if row['username'].to_s.strip.blank?
agent.email = row['email'].to_s.strip
agent.required_role = Role.find_by(name: row['required_role'].to_s.strip.camelize) || Role.find_by(name: 'Guest')
agent.email = row["email"].to_s.strip
agent.required_role = Role.find_by(name: row["required_role"].to_s.strip.camelize) || Role.find_by(name: "Guest")
# else
# agent.required_role = Role.where(name: row['required_role'].to_s.strip.camelize).first || Role.where('Librarian').first
# end
language = Language.find_by(name: row['language'].to_s.strip.camelize) || Language.find_by(iso_639_2: row['language'].to_s.strip.downcase) || Language.find_by(iso_639_1: row['language'].to_s.strip.downcase)
language = Language.find_by(name: row["language"].to_s.strip.camelize) || Language.find_by(iso_639_2: row["language"].to_s.strip.downcase) || Language.find_by(iso_639_1: row["language"].to_s.strip.downcase)
agent.language = language if language
country = Country.find_by(name: row['country'].to_s.strip)
country = Country.find_by(name: row["country"].to_s.strip)
agent.country = country if country
agent
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/agent_import_file_state_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class AgentImportFileStateMachine
state :completed
state :failed

transition from: :pending, to: [:started, :failed]
transition from: :started, to: [:completed, :failed]
transition from: :pending, to: [ :started, :failed ]
transition from: :started, to: [ :completed, :failed ]

after_transition(from: :pending, to: :started) do |agent_import_file|
agent_import_file.update_column(:executed_at, Time.zone.now)
Expand Down
4 changes: 2 additions & 2 deletions app/models/agent_import_result.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class AgentImportResult < ApplicationRecord
default_scope { order('agent_import_results.id') }
scope :file_id, proc{|file_id| where(agent_import_file_id: file_id)}
default_scope { order("agent_import_results.id") }
scope :file_id, proc { |file_id| where(agent_import_file_id: file_id) }
scope :failed, -> { where(agent_id: nil) }

belongs_to :agent_import_file
Expand Down
4 changes: 2 additions & 2 deletions app/models/agent_relationship.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class AgentRelationship < ApplicationRecord
belongs_to :parent, class_name: 'Agent'
belongs_to :child, class_name: 'Agent'
belongs_to :parent, class_name: "Agent"
belongs_to :child, class_name: "Agent"
belongs_to :agent_relationship_type, optional: true
validate :check_parent
acts_as_list scope: :parent_id
Expand Down
2 changes: 1 addition & 1 deletion app/models/agent_relationship_type.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class AgentRelationshipType < ApplicationRecord
include MasterModel
default_scope { order('agent_relationship_types.position') }
default_scope { order("agent_relationship_types.position") }
has_many :agent_relationships, dependent: :destroy
end

Expand Down
8 changes: 4 additions & 4 deletions app/models/basket.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Basket < ApplicationRecord
include EnjuCirculation::EnjuBasket
default_scope { order('baskets.id DESC') }
scope :will_expire, lambda {|date| where('created_at < ?', date)}
default_scope { order("baskets.id DESC") }
scope :will_expire, lambda { |date| where("created_at < ?", date) }
belongs_to :user, optional: true
has_many :accepts, dependent: :destroy
has_many :withdraws, dependent: :destroy
Expand All @@ -14,9 +14,9 @@ class Basket < ApplicationRecord

def check_suspended
if user
errors.add(:base, I18n.t('basket.this_account_is_suspended')) if user.locked_at
errors.add(:base, I18n.t("basket.this_account_is_suspended")) if user.locked_at
else
errors.add(:base, I18n.t('user.not_found'))
errors.add(:base, I18n.t("user.not_found"))
end
end

Expand Down
Loading

0 comments on commit bbe5f77

Please sign in to comment.