canvas_sync 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68b09dd9ca869bb37f08c0691ce54f1efa4abb7e
4
- data.tar.gz: 6615009014df4ddcd3b20e602549658fd659e0f9
3
+ metadata.gz: 450c9dd5440a29b40915b904cbbbe5eeeeff1c5d
4
+ data.tar.gz: 76035ff5b19e381ff046e6a57eec80943bb43254
5
5
  SHA512:
6
- metadata.gz: c7526df95cf7d7cd2a86d48c95ca57b4da54d9a6e94095318b0eefc5ec08dc37112072e0be0246b655715b21a0c593a0d49fbfc6cf44a6b5ad647ee6aa57188d
7
- data.tar.gz: 92b7dd1398562e07cacb45a5b5c54aac29ee4e366b090dbc5fec31e44690d4a211872c6dfe3d0b93c5aa71de5bff3f39da8f82d933f26484516a1fe875c17fd1
6
+ metadata.gz: eabefd522ae7150d7e9d5774440670fc647084ebad7786d3bd1b57dee0025d7a77607ffc923e16d76969986f29c6c47957042d3cf8873713676f284ac78d0aa0
7
+ data.tar.gz: 202029add66cc446630ba15c2a5816adbcdd2971085532d977e8cce40f365c5678d636833c9dd137b667bc18d27d25201d48da3b1ce7bb05f8c92b6003c8aee7
@@ -13,16 +13,25 @@ module CanvasSync
13
13
  # @param klass [Object] e.g., User
14
14
  # @param conflict_target [Symbol] represents the database column that will determine if we need to update
15
15
  # or insert a given row. e.g.,: canvas_user_id
16
+ # @param exclude_duplicates [Boolean] importing will break if the file has any duplicate rows. Set this
17
+ # to true in order to have the bulk importer filter those out.
16
18
  # @yieldparam [Array] row if a block is passed in it will yield the current row from the CSV.
17
19
  # This can be used if you need to filter or massage the data in any way.
18
- def self.import(report_file_path, mapping, klass, conflict_target)
20
+ def self.import(report_file_path, mapping, klass, conflict_target, exclude_duplicates=false)
19
21
  csv_column_names = mapping.keys
20
22
  database_column_names = mapping.values
21
23
  rows = []
24
+ row_ids = {}
22
25
 
23
26
  CSV.foreach(report_file_path, headers: true, header_converters: :symbol) do |row|
24
27
  row = yield(row) if block_given?
25
28
  next if row.nil?
29
+
30
+ if exclude_duplicates
31
+ next if row_ids[row[conflict_target]]
32
+ row_ids[row[conflict_target]] = true
33
+ end
34
+
26
35
  rows << csv_column_names.map { |column| row[column] }
27
36
 
28
37
  if rows.length >= batch_size
@@ -92,16 +92,12 @@ module CanvasSync
92
92
  end
93
93
 
94
94
  def self.process_users(report_file_path)
95
- rows = {}
96
-
97
- # Users can show up more than once in a report if they have multiple logins. This breaks
98
- # the bulk import, so the block we pass into the importer filters out users we've already
99
- # encountered.
100
- CanvasSync::Importers::BulkImporter.import(report_file_path, USERS_CSV_MAPPING, User, :canvas_user_id) do |row|
101
- next nil if rows[row[:canvas_user_id]]
102
- rows[row[:canvas_user_id]] = true
103
- row
104
- end
95
+ CanvasSync::Importers::BulkImporter.import(
96
+ report_file_path,
97
+ USERS_CSV_MAPPING,
98
+ User,
99
+ :canvas_user_id,
100
+ true)
105
101
  end
106
102
 
107
103
  def self.process_courses(report_file_path)
@@ -109,7 +105,12 @@ module CanvasSync
109
105
  end
110
106
 
111
107
  def self.process_enrollments(report_file_path)
112
- CanvasSync::Importers::BulkImporter.import(report_file_path, ENROLLMENTS_CSV_MAPPING, Enrollment, :canvas_enrollment_id)
108
+ CanvasSync::Importers::BulkImporter.import(
109
+ report_file_path,
110
+ ENROLLMENTS_CSV_MAPPING,
111
+ Enrollment,
112
+ :canvas_enrollment_id,
113
+ true)
113
114
  end
114
115
 
115
116
  def self.process_sections(report_file_path)
@@ -1,3 +1,3 @@
1
1
  module CanvasSync
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canvas_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nate Collings
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-18 00:00:00.000000000 Z
11
+ date: 2017-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -352,6 +352,7 @@ files:
352
352
  - spec/dummy/db/migrate/20170914181345_create_courses.rb
353
353
  - spec/dummy/db/migrate/20170918221413_create_users.rb
354
354
  - spec/dummy/db/schema.rb
355
+ - spec/dummy/db/test.sqlite3
355
356
  - spec/dummy/log/development.log
356
357
  - spec/dummy/log/test.log
357
358
  - spec/factories/course_factory.rb
@@ -435,6 +436,7 @@ test_files:
435
436
  - spec/dummy/db/migrate/20170914181345_create_courses.rb
436
437
  - spec/dummy/db/migrate/20170918221413_create_users.rb
437
438
  - spec/dummy/db/schema.rb
439
+ - spec/dummy/db/test.sqlite3
438
440
  - spec/dummy/log/development.log
439
441
  - spec/dummy/log/test.log
440
442
  - spec/factories/course_factory.rb