sheets_db 0.6.0 → 0.7.0
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/sheets_db/version.rb +1 -1
- data/lib/sheets_db/worksheet.rb +41 -2
- data/lib/sheets_db/worksheet/row.rb +10 -3
- 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: b7e907bf49b4cf4aa2db7e42de08bdb000c6f7aa
|
|
4
|
+
data.tar.gz: 5cecdaafb237db9ee78068370db3cd0f160c050d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 94b4e4ce9fc13adc72136d1a37c24bca8343415587230b840d3158c208b3d96ef05bd7025d5aadef166dc5f369e3124a0f80b5249c2cb6a3d1fad9101915a2c4
|
|
7
|
+
data.tar.gz: 365e9d23933c27732a87a0760630c89c12b4d12cd878e49084593d08693a337e595351eb19d6a65a60ed4971f3f8a4c74c0cc081267e1d7efbe066430e7075c3
|
data/lib/sheets_db/version.rb
CHANGED
data/lib/sheets_db/worksheet.rb
CHANGED
|
@@ -7,12 +7,13 @@ module SheetsDB
|
|
|
7
7
|
|
|
8
8
|
include Enumerable
|
|
9
9
|
|
|
10
|
-
attr_reader :spreadsheet, :google_drive_resource, :type
|
|
10
|
+
attr_reader :spreadsheet, :google_drive_resource, :type, :synchronizing
|
|
11
11
|
|
|
12
12
|
def initialize(spreadsheet:, google_drive_resource:, type:)
|
|
13
13
|
@spreadsheet = spreadsheet
|
|
14
14
|
@google_drive_resource = google_drive_resource
|
|
15
15
|
@type = type
|
|
16
|
+
@synchronizing = true
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
def ==(other)
|
|
@@ -81,7 +82,29 @@ module SheetsDB
|
|
|
81
82
|
assignment_value = attribute_definition[:multiple] ? value.join(",") : value
|
|
82
83
|
google_drive_resource[row_position, column.column_position] = assignment_value
|
|
83
84
|
end
|
|
84
|
-
google_drive_resource.synchronize
|
|
85
|
+
google_drive_resource.synchronize if synchronizing
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def next_available_row_position
|
|
89
|
+
google_drive_resource.num_rows + 1
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def new(**attributes)
|
|
93
|
+
type.new(worksheet: self, row_position: nil).tap { |row|
|
|
94
|
+
row.stage_attributes(attributes)
|
|
95
|
+
}
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def create!(**attributes)
|
|
99
|
+
new(**attributes).save!
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def import!(attribute_sets)
|
|
103
|
+
transaction do
|
|
104
|
+
attribute_sets.each do |attributes|
|
|
105
|
+
create!(**attributes)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
85
108
|
end
|
|
86
109
|
|
|
87
110
|
def each
|
|
@@ -147,5 +170,21 @@ module SheetsDB
|
|
|
147
170
|
attribute_definition[:transform].call(converted_value) :
|
|
148
171
|
converted_value
|
|
149
172
|
end
|
|
173
|
+
|
|
174
|
+
def enable_synchronization!
|
|
175
|
+
@synchronizing = true
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def disable_synchronization!
|
|
179
|
+
@synchronizing = false
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def transaction
|
|
183
|
+
disable_synchronization!
|
|
184
|
+
yield
|
|
185
|
+
google_drive_resource.synchronize
|
|
186
|
+
ensure
|
|
187
|
+
enable_synchronization!
|
|
188
|
+
end
|
|
150
189
|
end
|
|
151
190
|
end
|
|
@@ -110,6 +110,10 @@ module SheetsDB
|
|
|
110
110
|
@changed_foreign_items = []
|
|
111
111
|
end
|
|
112
112
|
|
|
113
|
+
def new_row?
|
|
114
|
+
row_position.nil?
|
|
115
|
+
end
|
|
116
|
+
|
|
113
117
|
def get_modified_attribute(name)
|
|
114
118
|
loaded_attributes.fetch(name, {}).
|
|
115
119
|
fetch(:changed)
|
|
@@ -164,15 +168,18 @@ module SheetsDB
|
|
|
164
168
|
end
|
|
165
169
|
|
|
166
170
|
def save!
|
|
171
|
+
assign_next_row_position_if_not_set
|
|
167
172
|
worksheet.update_attributes_at_row_position(staged_attributes, row_position: row_position)
|
|
168
173
|
save_changed_foreign_items!
|
|
169
174
|
reset_attributes_and_associations_cache
|
|
170
175
|
end
|
|
171
176
|
|
|
177
|
+
def assign_next_row_position_if_not_set
|
|
178
|
+
@row_position ||= worksheet.next_available_row_position
|
|
179
|
+
end
|
|
180
|
+
|
|
172
181
|
def save_changed_foreign_items!
|
|
173
|
-
changed_foreign_items.each
|
|
174
|
-
foreign_item.save!
|
|
175
|
-
end
|
|
182
|
+
changed_foreign_items.each(&:save!)
|
|
176
183
|
end
|
|
177
184
|
|
|
178
185
|
def reset_attributes_and_associations_cache
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sheets_db
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ravi Gadad
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-03-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: google_drive
|