activeresource-google_spreadsheets 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9fab4da8cf2bd56862ad443231e63792fced39e4
4
- data.tar.gz: 50f99e28d37b719d2460fbb803fc7ef751bde592
3
+ metadata.gz: a9fc307a84bd4cc4a57a66f9df28f3d3b5ce460a
4
+ data.tar.gz: 52a30d70cc2357bf3e7b453ffee1d13ca441c9d8
5
5
  SHA512:
6
- metadata.gz: bba764383492d89a8e64b1d6aab8117f162afbeb42cd9290dc06014e495f7f1d7b5f491488a5f50cfa268eb9c827b21559949f240933674577693efb29958e3c
7
- data.tar.gz: a8db6ca3c03781c425faaf96b673dde4485a37f6ce0bef47eca3c625a6d4e2c8eaa8bf045d38200d36828defaf454eeff81769d0535f0e791d89420fc30c74bb
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
- record_id = row.id.to_i
77
- record = records_to_save[record_id] || record_class.find_or_initialize_by(id: record_id)
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.instance_variable_set(:@due_to_destroy, true)
81
- records_to_save[row.id.to_i] = record
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[row.id.to_i] = record
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.instance_variable_get(:@due_to_destroy)
103
+ if record.marked_for_destruction?
97
104
  record.destroy
98
105
  else
99
106
  record.save
@@ -1,3 +1,3 @@
1
1
  module GoogleSpreadsheets
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
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
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-02-04 00:00:00.000000000 Z
12
+ date: 2015-06-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activeresource