Skip to content

Commit bbe5f77

Browse files
committed
apply rubocop
1 parent 25c9b4c commit bbe5f77

File tree

116 files changed

+1160
-1160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+1160
-1160
lines changed

app/models/accept.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
class Accept < ApplicationRecord
22
include EnjuCirculation::EnjuAccept
3-
default_scope { order('accepts.id DESC') }
3+
default_scope { order("accepts.id DESC") }
44
belongs_to :basket
55
belongs_to :item, touch: true
6-
belongs_to :librarian, class_name: 'User'
6+
belongs_to :librarian, class_name: "User"
77

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

app/models/agent.rb

+37-37
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
class Agent < ApplicationRecord
22
include EnjuNdl::EnjuAgent
33

4-
scope :readable_by, lambda{ |user|
4+
scope :readable_by, lambda { |user|
55
if user
6-
where('required_role_id <= ?', user.try(:user_has_role).try(:role_id))
6+
where("required_role_id <= ?", user.try(:user_has_role).try(:role_id))
77
else
8-
where('required_role_id <= 1')
8+
where("required_role_id <= 1")
99
end
1010
}
1111
has_many :creates, dependent: :destroy
@@ -14,8 +14,8 @@ class Agent < ApplicationRecord
1414
has_many :expressions, through: :realizes
1515
has_many :produces, dependent: :destroy
1616
has_many :manifestations, through: :produces
17-
has_many :children, foreign_key: 'parent_id', class_name: 'AgentRelationship', dependent: :destroy, inverse_of: :parent
18-
has_many :parents, foreign_key: 'child_id', class_name: 'AgentRelationship', dependent: :destroy, inverse_of: :child
17+
has_many :children, foreign_key: "parent_id", class_name: "AgentRelationship", dependent: :destroy, inverse_of: :parent
18+
has_many :parents, foreign_key: "child_id", class_name: "AgentRelationship", dependent: :destroy, inverse_of: :child
1919
has_many :derived_agents, through: :children, source: :child
2020
has_many :original_agents, through: :parents, source: :parent
2121
has_many :picture_files, as: :picture_attachable, dependent: :destroy
@@ -26,7 +26,7 @@ class Agent < ApplicationRecord
2626
has_many :agent_merges, dependent: :destroy
2727
has_many :agent_merge_lists, through: :agent_merges
2828
belongs_to :agent_type
29-
belongs_to :required_role, class_name: 'Role'
29+
belongs_to :required_role, class_name: "Role"
3030
belongs_to :language
3131
belongs_to :country
3232
has_one :agent_import_result
@@ -40,17 +40,17 @@ class Agent < ApplicationRecord
4040
before_validation :set_role_and_name, on: :create
4141
before_save :set_date_of_birth, :set_date_of_death
4242
after_save do |agent|
43-
agent.works.map{|work| work.touch && work.index}
44-
agent.expressions.map{|expression| expression.touch && expression.index}
45-
agent.manifestations.map{|manifestation| manifestation.touch && manifestation.index}
46-
agent.items.map{|item| item.touch && item.index}
43+
agent.works.map { |work| work.touch && work.index }
44+
agent.expressions.map { |expression| expression.touch && expression.index }
45+
agent.manifestations.map { |manifestation| manifestation.touch && manifestation.index }
46+
agent.items.map { |item| item.touch && item.index }
4747
Sunspot.commit
4848
end
4949
after_destroy do |agent|
50-
agent.works.map{|work| work.touch && work.index}
51-
agent.expressions.map{|expression| expression.touch && expression.index}
52-
agent.manifestations.map{|manifestation| manifestation.touch && manifestation.index}
53-
agent.items.map{|item| item.touch && item.index}
50+
agent.works.map { |work| work.touch && work.index }
51+
agent.expressions.map { |expression| expression.touch && expression.index }
52+
agent.manifestations.map { |manifestation| manifestation.touch && manifestation.index }
53+
agent.items.map { |item| item.touch && item.index }
5454
Sunspot.commit
5555
end
5656

@@ -79,22 +79,22 @@ class Agent < ApplicationRecord
7979
paginates_per 10
8080

8181
def set_role_and_name
82-
self.required_role = Role.find_by(name: 'Librarian') if required_role_id.nil?
82+
self.required_role = Role.find_by(name: "Librarian") if required_role_id.nil?
8383
set_full_name
8484
end
8585

8686
def set_full_name
8787
if full_name.blank?
8888
if LibraryGroup.site_config.family_name_first
89-
self.full_name = [last_name, middle_name, first_name].compact.join(" ").to_s.strip
89+
self.full_name = [ last_name, middle_name, first_name ].compact.join(" ").to_s.strip
9090
else
91-
self.full_name = [first_name, last_name, middle_name].compact.join(" ").to_s.strip
91+
self.full_name = [ first_name, last_name, middle_name ].compact.join(" ").to_s.strip
9292
end
9393
end
9494
if full_name_transcription.blank?
95-
self.full_name_transcription = [last_name_transcription, middle_name_transcription, first_name_transcription].join(" ").to_s.strip
95+
self.full_name_transcription = [ last_name_transcription, middle_name_transcription, first_name_transcription ].join(" ").to_s.strip
9696
end
97-
[full_name, full_name_transcription]
97+
[ full_name, full_name_transcription ]
9898
end
9999

100100
def set_date_of_birth
@@ -145,15 +145,15 @@ def check_birth_date
145145
end
146146
end
147147

148-
#def full_name_generate
148+
# def full_name_generate
149149
# # TODO: 日本人以外は?
150150
# name = []
151151
# name << self.last_name.to_s.strip
152152
# name << self.middle_name.to_s.strip unless self.middle_name.blank?
153153
# name << self.first_name.to_s.strip
154154
# name << self.corporate_name.to_s.strip
155155
# name.join(" ").strip
156-
#end
156+
# end
157157

158158
def full_name_without_space
159159
full_name.gsub(/[\s,]/, "")
@@ -180,11 +180,11 @@ def name
180180
name << full_name_transcription.to_s.strip
181181
name << full_name_alternative.to_s.strip
182182
name << full_name_without_space
183-
#name << full_name_transcription_without_space
184-
#name << full_name_alternative_without_space
185-
#name << full_name.wakati rescue nil
186-
#name << full_name_transcription.wakati rescue nil
187-
#name << full_name_alternative.wakati rescue nil
183+
# name << full_name_transcription_without_space
184+
# name << full_name_alternative_without_space
185+
# name << full_name.wakati rescue nil
186+
# name << full_name_transcription.wakati rescue nil
187+
# name << full_name_alternative.wakati rescue nil
188188
name
189189
end
190190

@@ -225,7 +225,7 @@ def owned(item)
225225
def self.import_agents(agent_lists)
226226
agents = []
227227
agent_lists.each do |agent_list|
228-
name_and_role = agent_list[:full_name].split('||')
228+
name_and_role = agent_list[:full_name].split("||")
229229
if agent_list[:ndla_identifier].present?
230230
agent = NdlaRecord.find_by(body: agent_list[:ndla_identifier])&.agent
231231
elsif agent_list[:agent_identifier].present?
@@ -245,7 +245,7 @@ def self.import_agents(agent_lists)
245245
place: agent_list[:place],
246246
language_id: 1
247247
)
248-
agent.required_role = Role.find_by(name: 'Guest')
248+
agent.required_role = Role.find_by(name: "Guest")
249249
agent.save
250250

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

273273
agent = nil
274274

275-
if v['agent_id'].present?
276-
agent = Agent.find(v['agent_id'])
277-
elsif v['id'].present?
278-
agent = Agent.find(v['id'])
275+
if v["agent_id"].present?
276+
agent = Agent.find(v["agent_id"])
277+
elsif v["id"].present?
278+
agent = Agent.find(v["id"])
279279
end
280280

281-
if !agent or agent.full_name != v['full_name']
282-
v.delete('id')
283-
v.delete('agent_id')
284-
v.delete('_destroy')
281+
if !agent or agent.full_name != v["full_name"]
282+
v.delete("id")
283+
v.delete("agent_id")
284+
v.delete("_destroy")
285285
agent = Agent.create(v)
286286
end
287287

app/models/agent_import_file.rb

+47-47
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ class AgentImportFile < ApplicationRecord
44
initial_state: AgentImportFileStateMachine.initial_state
55
]
66
include ImportFile
7-
default_scope { order('agent_import_files.id DESC') }
7+
default_scope { order("agent_import_files.id DESC") }
88
scope :not_imported, -> { in_state(:pending) }
9-
scope :stucked, -> { in_state(:pending).where('agent_import_files.created_at < ?', 1.hour.ago) }
9+
scope :stucked, -> { in_state(:pending).where("agent_import_files.created_at < ?", 1.hour.ago) }
1010

1111
has_one_attached :attachment
1212
belongs_to :user
@@ -25,11 +25,11 @@ def state_machine
2525

2626
def import_start
2727
case edit_mode
28-
when 'create'
28+
when "create"
2929
import
30-
when 'update'
30+
when "update"
3131
modify
32-
when 'destroy'
32+
when "destroy"
3333
remove
3434
else
3535
import
@@ -42,17 +42,17 @@ def import
4242
rows = open_import_file
4343
field = rows.first
4444
row_num = 1
45-
if [field['first_name'], field['last_name'], field['full_name']].reject{|field| field.to_s.strip == ""}.empty?
45+
if [ field["first_name"], field["last_name"], field["full_name"] ].reject { |field| field.to_s.strip == "" }.empty?
4646
raise "You should specify first_name, last_name or full_name in the first line"
4747
end
4848

49-
#rows.shift
49+
# rows.shift
5050

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

5757
agent = Agent.new
5858
agent = set_agent_value(agent, row)
@@ -94,21 +94,21 @@ def modify
9494

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

99-
agent = Agent.find_by(id: row['id'])
99+
agent = Agent.find_by(id: row["id"])
100100
next unless agent
101101

102-
agent.full_name = row['full_name'] if row['full_name'].to_s.strip.present?
103-
agent.full_name_transcription = row['full_name_transcription'] if row['full_name_transcription'].to_s.strip.present?
104-
agent.first_name = row['first_name'] if row['first_name'].to_s.strip.present?
105-
agent.first_name_transcription = row['first_name_transcription'] if row['first_name_transcription'].to_s.strip.present?
106-
agent.middle_name = row['middle_name'] if row['middle_name'].to_s.strip.present?
107-
agent.middle_name_transcription = row['middle_name_transcription'] if row['middle_name_transcription'].to_s.strip.present?
108-
agent.last_name = row['last_name'] if row['last_name'].to_s.strip.present?
109-
agent.last_name_transcription = row['last_name_transcription'] if row['last_name_transcription'].to_s.strip.present?
110-
agent.address_1 = row['address_1'] if row['address_1'].to_s.strip.present?
111-
agent.address_2 = row['address_2'] if row['address_2'].to_s.strip.present?
102+
agent.full_name = row["full_name"] if row["full_name"].to_s.strip.present?
103+
agent.full_name_transcription = row["full_name_transcription"] if row["full_name_transcription"].to_s.strip.present?
104+
agent.first_name = row["first_name"] if row["first_name"].to_s.strip.present?
105+
agent.first_name_transcription = row["first_name_transcription"] if row["first_name_transcription"].to_s.strip.present?
106+
agent.middle_name = row["middle_name"] if row["middle_name"].to_s.strip.present?
107+
agent.middle_name_transcription = row["middle_name_transcription"] if row["middle_name_transcription"].to_s.strip.present?
108+
agent.last_name = row["last_name"] if row["last_name"].to_s.strip.present?
109+
agent.last_name_transcription = row["last_name_transcription"] if row["last_name_transcription"].to_s.strip.present?
110+
agent.address_1 = row["address_1"] if row["address_1"].to_s.strip.present?
111+
agent.address_2 = row["address_2"] if row["address_2"].to_s.strip.present?
112112
agent.save!
113113
end
114114
transition_to!(:completed)
@@ -130,9 +130,9 @@ def remove
130130

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

135-
agent = Agent.find_by(id: row['id'].to_s.strip)
135+
agent = Agent.find_by(id: row["id"].to_s.strip)
136136
next unless agent
137137

138138
agent.picture_files.destroy_all
@@ -166,37 +166,37 @@ def open_import_file
166166
end
167167

168168
def set_agent_value(agent, row)
169-
agent.first_name = row['first_name'] if row['first_name']
170-
agent.middle_name = row['middle_name'] if row['middle_name']
171-
agent.last_name = row['last_name'] if row['last_name']
172-
agent.first_name_transcription = row['first_name_transcription'] if row['first_name_transcription']
173-
agent.middle_name_transcription = row['middle_name_transcription'] if row['middle_name_transcription']
174-
agent.last_name_transcription = row['last_name_transcription'] if row['last_name_transcription']
175-
176-
agent.full_name = row['full_name'] if row['full_name']
177-
agent.full_name_transcription = row['full_name_transcription'] if row['full_name_transcription']
178-
179-
agent.address_1 = row['address_1'] if row['address_1']
180-
agent.address_2 = row['address_2'] if row['address_2']
181-
agent.zip_code_1 = row['zip_code_1'] if row['zip_code_1']
182-
agent.zip_code_2 = row['zip_code_2'] if row['zip_code_2']
183-
agent.telephone_number_1 = row['telephone_number_1'] if row['telephone_number_1']
184-
agent.telephone_number_2 = row['telephone_number_2'] if row['telephone_number_2']
185-
agent.fax_number_1 = row['fax_number_1'] if row['fax_number_1']
186-
agent.fax_number_2 = row['fax_number_2'] if row['fax_number_2']
187-
agent.note = row['note'] if row['note']
188-
agent.birth_date = row['birth_date'] if row['birth_date']
189-
agent.death_date = row['death_date'] if row['death_date']
169+
agent.first_name = row["first_name"] if row["first_name"]
170+
agent.middle_name = row["middle_name"] if row["middle_name"]
171+
agent.last_name = row["last_name"] if row["last_name"]
172+
agent.first_name_transcription = row["first_name_transcription"] if row["first_name_transcription"]
173+
agent.middle_name_transcription = row["middle_name_transcription"] if row["middle_name_transcription"]
174+
agent.last_name_transcription = row["last_name_transcription"] if row["last_name_transcription"]
175+
176+
agent.full_name = row["full_name"] if row["full_name"]
177+
agent.full_name_transcription = row["full_name_transcription"] if row["full_name_transcription"]
178+
179+
agent.address_1 = row["address_1"] if row["address_1"]
180+
agent.address_2 = row["address_2"] if row["address_2"]
181+
agent.zip_code_1 = row["zip_code_1"] if row["zip_code_1"]
182+
agent.zip_code_2 = row["zip_code_2"] if row["zip_code_2"]
183+
agent.telephone_number_1 = row["telephone_number_1"] if row["telephone_number_1"]
184+
agent.telephone_number_2 = row["telephone_number_2"] if row["telephone_number_2"]
185+
agent.fax_number_1 = row["fax_number_1"] if row["fax_number_1"]
186+
agent.fax_number_2 = row["fax_number_2"] if row["fax_number_2"]
187+
agent.note = row["note"] if row["note"]
188+
agent.birth_date = row["birth_date"] if row["birth_date"]
189+
agent.death_date = row["death_date"] if row["death_date"]
190190

191191
# if row['username'].to_s.strip.blank?
192-
agent.email = row['email'].to_s.strip
193-
agent.required_role = Role.find_by(name: row['required_role'].to_s.strip.camelize) || Role.find_by(name: 'Guest')
192+
agent.email = row["email"].to_s.strip
193+
agent.required_role = Role.find_by(name: row["required_role"].to_s.strip.camelize) || Role.find_by(name: "Guest")
194194
# else
195195
# agent.required_role = Role.where(name: row['required_role'].to_s.strip.camelize).first || Role.where('Librarian').first
196196
# end
197-
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)
197+
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)
198198
agent.language = language if language
199-
country = Country.find_by(name: row['country'].to_s.strip)
199+
country = Country.find_by(name: row["country"].to_s.strip)
200200
agent.country = country if country
201201
agent
202202
end

app/models/agent_import_file_state_machine.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ class AgentImportFileStateMachine
66
state :completed
77
state :failed
88

9-
transition from: :pending, to: [:started, :failed]
10-
transition from: :started, to: [:completed, :failed]
9+
transition from: :pending, to: [ :started, :failed ]
10+
transition from: :started, to: [ :completed, :failed ]
1111

1212
after_transition(from: :pending, to: :started) do |agent_import_file|
1313
agent_import_file.update_column(:executed_at, Time.zone.now)

app/models/agent_import_result.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class AgentImportResult < ApplicationRecord
2-
default_scope { order('agent_import_results.id') }
3-
scope :file_id, proc{|file_id| where(agent_import_file_id: file_id)}
2+
default_scope { order("agent_import_results.id") }
3+
scope :file_id, proc { |file_id| where(agent_import_file_id: file_id) }
44
scope :failed, -> { where(agent_id: nil) }
55

66
belongs_to :agent_import_file

app/models/agent_relationship.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class AgentRelationship < ApplicationRecord
2-
belongs_to :parent, class_name: 'Agent'
3-
belongs_to :child, class_name: 'Agent'
2+
belongs_to :parent, class_name: "Agent"
3+
belongs_to :child, class_name: "Agent"
44
belongs_to :agent_relationship_type, optional: true
55
validate :check_parent
66
acts_as_list scope: :parent_id

app/models/agent_relationship_type.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class AgentRelationshipType < ApplicationRecord
22
include MasterModel
3-
default_scope { order('agent_relationship_types.position') }
3+
default_scope { order("agent_relationship_types.position") }
44
has_many :agent_relationships, dependent: :destroy
55
end
66

app/models/basket.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Basket < ApplicationRecord
22
include EnjuCirculation::EnjuBasket
3-
default_scope { order('baskets.id DESC') }
4-
scope :will_expire, lambda {|date| where('created_at < ?', date)}
3+
default_scope { order("baskets.id DESC") }
4+
scope :will_expire, lambda { |date| where("created_at < ?", date) }
55
belongs_to :user, optional: true
66
has_many :accepts, dependent: :destroy
77
has_many :withdraws, dependent: :destroy
@@ -14,9 +14,9 @@ class Basket < ApplicationRecord
1414

1515
def check_suspended
1616
if user
17-
errors.add(:base, I18n.t('basket.this_account_is_suspended')) if user.locked_at
17+
errors.add(:base, I18n.t("basket.this_account_is_suspended")) if user.locked_at
1818
else
19-
errors.add(:base, I18n.t('user.not_found'))
19+
errors.add(:base, I18n.t("user.not_found"))
2020
end
2121
end
2222

0 commit comments

Comments
 (0)