activeresource-google_spreadsheets 0.1.0 → 0.1.1

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: 59691c2bd7817f25d8065105e5b357aee2506080
4
- data.tar.gz: 4d3ae79b0a0bb0e9f6120de3507ce1cd2d82eb3b
3
+ metadata.gz: 3dca8fdf8c0b4b8098cb273093e2105e1787f7d1
4
+ data.tar.gz: 1ef5641b07c1e1396382a8fcd8e7a4b2237588e1
5
5
  SHA512:
6
- metadata.gz: b47e0295e67c174828bb4bffbf66bd3623d89cd650c89f04bbca2596522065ada1f5ab18375f69f84e95b75b2a46b8e0101f1ec8549ed939c565be81f07a5f1f
7
- data.tar.gz: 587b14efafcc01ebcff5cfdc88e290b025407598ddab283a7303bfa00a25aa04ad73daee92bda425ce5343dbde49ca330f216d3a60ca674a484364314eb540fb
6
+ metadata.gz: 18622284721fdc4bbdbffb035f26bc00567acc21c877085e13cae44253973843fd097872faad4eee3e15709cc927ecf56a26f52580f42a80d68d6a4edcfd2d7f
7
+ data.tar.gz: df53e2409d044333c83fd7d0c94911c69a1749b111a1e8eaacf1cb03cd06198ec28b2277aeec3a13b8308c0639dfb789738a20820305b3ad2124f7622353877d
@@ -65,6 +65,10 @@ module GoogleSpreadsheets
65
65
  (self.class.known_attributes + gsx_attributes - self.class._ignore_attributes).uniq
66
66
  end
67
67
 
68
+ def all_values_empty?
69
+ self.attributes.select{|k, v| k.to_s.start_with?('gsx:') && k.to_s != 'gsx:id' }.values.all?{|v| v == '' }
70
+ end
71
+
68
72
  def respond_to?(method, include_priv = false)
69
73
  method_name = method.to_s
70
74
  ((matches = method_name.match(/(=|\?)$/)) && attributes.include?("gsx:#{matches.pre_match}")) ||
@@ -70,17 +70,28 @@ module GoogleSpreadsheets
70
70
  reset
71
71
  records = all_rows.map do |row|
72
72
  record_class.find_or_initialize_by(id: row.id).tap do |record|
73
- row.aliased_attributes.each do |attr|
74
- value = row.send(attr)
75
- if options[:include_blank] || value.present?
76
- record.send("#{attr}=", value)
73
+ if row.all_values_empty?
74
+ # Due to destroy if exists
75
+ record.instance_variable_set(:@due_to_destroy, true)
76
+ else
77
+ row.aliased_attributes.each do |attr|
78
+ value = row.send(attr)
79
+ if options[:include_blank] || value.present?
80
+ record.send("#{attr}=", value)
81
+ end
77
82
  end
78
83
  end
79
84
  end
80
85
  end
81
86
  skipping_outbound_sync_of(records) do |records_with_skipped_outbound|
82
87
  transaction_if_possible(record_class) do
83
- records_with_skipped_outbound.each(&:save)
88
+ records_with_skipped_outbound.each do |record|
89
+ if record.instance_variable_get(:@due_to_destroy)
90
+ record.destroy
91
+ else
92
+ record.save
93
+ end
94
+ end
84
95
  end
85
96
  end
86
97
  end
@@ -1,3 +1,3 @@
1
1
  module GoogleSpreadsheets
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
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.0
4
+ version: 0.1.1
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: 2014-11-17 00:00:00.000000000 Z
12
+ date: 2014-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activeresource