1
1
class Agent < ApplicationRecord
2
2
include EnjuNdl ::EnjuAgent
3
3
4
- scope :readable_by , lambda { |user |
4
+ scope :readable_by , lambda { |user |
5
5
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 ) )
7
7
else
8
- where ( ' required_role_id <= 1' )
8
+ where ( " required_role_id <= 1" )
9
9
end
10
10
}
11
11
has_many :creates , dependent : :destroy
@@ -14,8 +14,8 @@ class Agent < ApplicationRecord
14
14
has_many :expressions , through : :realizes
15
15
has_many :produces , dependent : :destroy
16
16
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
19
19
has_many :derived_agents , through : :children , source : :child
20
20
has_many :original_agents , through : :parents , source : :parent
21
21
has_many :picture_files , as : :picture_attachable , dependent : :destroy
@@ -26,7 +26,7 @@ class Agent < ApplicationRecord
26
26
has_many :agent_merges , dependent : :destroy
27
27
has_many :agent_merge_lists , through : :agent_merges
28
28
belongs_to :agent_type
29
- belongs_to :required_role , class_name : ' Role'
29
+ belongs_to :required_role , class_name : " Role"
30
30
belongs_to :language
31
31
belongs_to :country
32
32
has_one :agent_import_result
@@ -40,17 +40,17 @@ class Agent < ApplicationRecord
40
40
before_validation :set_role_and_name , on : :create
41
41
before_save :set_date_of_birth , :set_date_of_death
42
42
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 }
47
47
Sunspot . commit
48
48
end
49
49
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 }
54
54
Sunspot . commit
55
55
end
56
56
@@ -79,22 +79,22 @@ class Agent < ApplicationRecord
79
79
paginates_per 10
80
80
81
81
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?
83
83
set_full_name
84
84
end
85
85
86
86
def set_full_name
87
87
if full_name . blank?
88
88
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
90
90
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
92
92
end
93
93
end
94
94
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
96
96
end
97
- [ full_name , full_name_transcription ]
97
+ [ full_name , full_name_transcription ]
98
98
end
99
99
100
100
def set_date_of_birth
@@ -145,15 +145,15 @@ def check_birth_date
145
145
end
146
146
end
147
147
148
- #def full_name_generate
148
+ # def full_name_generate
149
149
# # TODO: 日本人以外は?
150
150
# name = []
151
151
# name << self.last_name.to_s.strip
152
152
# name << self.middle_name.to_s.strip unless self.middle_name.blank?
153
153
# name << self.first_name.to_s.strip
154
154
# name << self.corporate_name.to_s.strip
155
155
# name.join(" ").strip
156
- #end
156
+ # end
157
157
158
158
def full_name_without_space
159
159
full_name . gsub ( /[\s ,]/ , "" )
@@ -180,11 +180,11 @@ def name
180
180
name << full_name_transcription . to_s . strip
181
181
name << full_name_alternative . to_s . strip
182
182
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
188
188
name
189
189
end
190
190
@@ -225,7 +225,7 @@ def owned(item)
225
225
def self . import_agents ( agent_lists )
226
226
agents = [ ]
227
227
agent_lists . each do |agent_list |
228
- name_and_role = agent_list [ :full_name ] . split ( '||' )
228
+ name_and_role = agent_list [ :full_name ] . split ( "||" )
229
229
if agent_list [ :ndla_identifier ] . present?
230
230
agent = NdlaRecord . find_by ( body : agent_list [ :ndla_identifier ] ) &.agent
231
231
elsif agent_list [ :agent_identifier ] . present?
@@ -245,7 +245,7 @@ def self.import_agents(agent_lists)
245
245
place : agent_list [ :place ] ,
246
246
language_id : 1
247
247
)
248
- agent . required_role = Role . find_by ( name : ' Guest' )
248
+ agent . required_role = Role . find_by ( name : " Guest" )
249
249
agent . save
250
250
251
251
if agent_list [ :ndla_identifier ] . present?
@@ -268,20 +268,20 @@ def self.new_agents(agents_params)
268
268
agents = [ ]
269
269
Agent . transaction do
270
270
agents_params . each do |k , v |
271
- next if v [ ' _destroy' ] == '1'
271
+ next if v [ " _destroy" ] == "1"
272
272
273
273
agent = nil
274
274
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" ] )
279
279
end
280
280
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" )
285
285
agent = Agent . create ( v )
286
286
end
287
287
0 commit comments