activeresource-google_spreadsheets 0.1.4 → 0.1.5
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 +4 -4
- data/lib/google_spreadsheets/enhanced/syncing.rb +14 -7
- data/lib/google_spreadsheets/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9fc307a84bd4cc4a57a66f9df28f3d3b5ce460a
|
4
|
+
data.tar.gz: 52a30d70cc2357bf3e7b453ffee1d13ca441c9d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bb50b09aac1eb0f9edf45f7ab5a93faf0f091defb84e3dee046c79a5c95901c29d0576894b08a2cb16b50cf18e7018f893b59acfb2785bd109aa90d7c853d45
|
7
|
+
data.tar.gz: ff50e9299126eea1661bf4129e649dd7378a7a474b36e6a025278c46a0b24cab87d4acaee88057fd2e67677f50d19c40b33b381dbd8d10cb54fb9b8c6d5a8e75
|
@@ -19,7 +19,7 @@ module GoogleSpreadsheets
|
|
19
19
|
# worksheet_title: 'users'
|
20
20
|
# after_commit :sync_user_row
|
21
21
|
def sync_with(rows_name, options)
|
22
|
-
options.assert_valid_keys(:spreadsheet_id, :worksheet_title, :class_name, :assigner, :include_blank)
|
22
|
+
options.assert_valid_keys(:spreadsheet_id, :worksheet_title, :class_name, :assigner, :include_blank, :ignore_blank_id)
|
23
23
|
opts = options.dup
|
24
24
|
spreadsheet_id = opts.delete(:spreadsheet_id)
|
25
25
|
worksheet_title = opts.delete(:worksheet_title) || rows_name.to_s
|
@@ -73,12 +73,19 @@ module GoogleSpreadsheets
|
|
73
73
|
reset
|
74
74
|
records_to_save = {}
|
75
75
|
all_rows.each do |row|
|
76
|
-
|
77
|
-
|
76
|
+
if row.id.present?
|
77
|
+
record_id = row.id.to_i
|
78
|
+
record = records_to_save[record_id] || record_class.find_or_initialize_by(id: record_id)
|
79
|
+
elsif !@options[:ignore_blank_id]
|
80
|
+
record_id = SecureRandom.hex(8) # dummy id
|
81
|
+
record = record_class.new
|
82
|
+
else
|
83
|
+
next
|
84
|
+
end
|
78
85
|
if row.all_values_empty?
|
79
86
|
# Due to destroy if exists
|
80
|
-
record.
|
81
|
-
records_to_save[
|
87
|
+
record.mark_for_destruction
|
88
|
+
records_to_save[record_id] = record
|
82
89
|
next
|
83
90
|
end
|
84
91
|
row_attributes = Hash[row.aliased_attributes.map{|attr| [attr, row.send(attr)] }]
|
@@ -88,12 +95,12 @@ module GoogleSpreadsheets
|
|
88
95
|
else
|
89
96
|
assign_row_attributes(record, row_attributes)
|
90
97
|
end
|
91
|
-
records_to_save[
|
98
|
+
records_to_save[record_id] = record
|
92
99
|
end
|
93
100
|
skipping_outbound_sync_of(records_to_save.values) do |records_with_skipped_outbound|
|
94
101
|
transaction_if_possible(record_class) do
|
95
102
|
records_with_skipped_outbound.each do |record|
|
96
|
-
if record.
|
103
|
+
if record.marked_for_destruction?
|
97
104
|
record.destroy
|
98
105
|
else
|
99
106
|
record.save
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeresource-google_spreadsheets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chihiro Ito
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-06-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activeresource
|