Class: PeopleUpdater
Overview
handles people.csv and splits out family data for FamilyUpdater
Constant Summary
collapse
- @@required_columns =
%w(legacy_id legacy_family_id)
Constants inherited
from UpdateAgent
UpdateAgent::MAX_HASHES_AT_A_TIME, UpdateAgent::MAX_TO_BATCH_AT_A_TIME, UpdateAgent::RETRIES, UpdateAgent::RETRY_SLEEP, UpdateAgent::SLEEP_PERIOD
Instance Attribute Summary
Attributes inherited from UpdateAgent
#attributes, #create, #data, #sync, #update
Instance Method Summary
collapse
Methods inherited from UpdateAgent
#check_for_invalid_columns, #confirm, #data_by_id, #errors, #ids, #legacy_ids, #present_record, #read_from_file, #resource, #send_notification, #start_sync, #to_sync_item
Constructor Details
#initialize(filename, options = {}) ⇒ PeopleUpdater
split out family data and create a new FamilyUpdater
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/updateagent/updaters/people_updater.rb', line 6
def initialize(filename, options={})
super(filename, options)
if options['converter']
converter = Kernel.const_get(@options['converter']['name'] + 'Converter').new(@options['converter'])
@data = converter.convert(@data.clone)
@attributes = @data.first.keys
end
check_for_missing_columns
person_data = []
family_data = {}
@data.each_with_index do |row, index|
person, family = split_change_hash(row)
if person.has_key?('email')
person['email_changed'] = false
end
if person.has_key?('relationships') and rels = person['relationships'].split(',').sort.join(',')
person['relationships_hash'] = Digest::SHA1.hexdigest(rels)
end
if existing_family = family_data[family['legacy_id']]
person['family'] = existing_family
person_data << person
else
person['family'] = family
person_data << person
family['barcode_id_changed'] = false if family.has_key?('barcode_id')
family_data[family['legacy_id']] = family
end
print "splitting family record #{index+1}\r"
end
puts
@attributes << 'email_changed' if @attributes.include?('email')
if @attributes.include?('relationships')
@attributes << 'relationships_hash'
@attributes.delete('relationships')
end
@data = person_data
@attributes.reject! { |a| a =~ /^family_/ and a != 'family_id' }
@family_agent = FamilyUpdater.new(family_data.values, @options)
end
|
Instance Method Details
#check_for_missing_columns ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/updateagent/updaters/people_updater.rb', line 50
def check_for_missing_columns
if row = @data.detect { |row| (@@required_columns - row.keys).any? }
puts "Error: one or more required columns are missing."
puts "Required but missing: #{(@@required_columns - row.keys).join(', ')}"
exit(1)
end
end
|
#compare(force = false) ⇒ Object
62
63
64
65
|
# File 'lib/updateagent/updaters/people_updater.rb', line 62
def compare(force=false)
@family_agent.compare(force)
super(force)
end
|
#create_count ⇒ Object
76
77
78
|
# File 'lib/updateagent/updaters/people_updater.rb', line 76
def create_count
@create.length + @family_agent.create.length
end
|
#finish_sync(create_items = true, mark_complete = true) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/updateagent/updaters/people_updater.rb', line 89
def finish_sync(create_items=true, mark_complete=true)
if create_items
@family_agent.sync = @sync
@family_agent.finish_sync(true, false)
super(true, false)
end
if mark_complete
@sync.complete = true
@sync.error_count = errors.length + @family_agent.errors.length
@sync.success_count = (@create + @update).length + (@family_agent.create + @family_agent.update).length - @sync.error_count
@sync.save
end
end
|
#has_work? ⇒ Boolean
67
68
69
|
# File 'lib/updateagent/updaters/people_updater.rb', line 67
def has_work?
@family_agent.has_work? or super
end
|
#name_for(row) ⇒ Object
58
59
60
|
# File 'lib/updateagent/updaters/people_updater.rb', line 58
def name_for(row)
"#{row['first_name']} #{row['last_name']}" rescue ''
end
|
#present ⇒ Object
71
72
73
74
|
# File 'lib/updateagent/updaters/people_updater.rb', line 71
def present
@family_agent.present if @family_agent.has_work?
super
end
|
#push ⇒ Object
84
85
86
87
|
# File 'lib/updateagent/updaters/people_updater.rb', line 84
def push
@family_agent.push
super
end
|
#update_count ⇒ Object
80
81
82
|
# File 'lib/updateagent/updaters/people_updater.rb', line 80
def update_count
@update.length + @family_agent.update.length
end
|