sheets_db 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sheets_db/spreadsheet.rb +18 -9
- data/lib/sheets_db/version.rb +1 -1
- data/lib/sheets_db/worksheet.rb +6 -2
- 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: c37bce0986d7a7d4519d7c1de690e5ccd8478b0c
|
4
|
+
data.tar.gz: 463046931944f6c506cdf0513ea57143a5b1a5f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e20974a3ee065f6ed76aa1aa768f6457bdf609b0841da88ab2a16ae77cc3e255f5bd9c9737c231ba75083d91847f1d4618d1bb5e3bb02e09d75421a25e6ebf9
|
7
|
+
data.tar.gz: 7067fd579b021d5378b7e09d0e1ba77060aadce98c63d6a04ed4664395f0a56e64278fb6afec6552f717628d720d54480c69904e3427cb063792bb3fad769296
|
@@ -1,19 +1,13 @@
|
|
1
1
|
module SheetsDB
|
2
2
|
class Spreadsheet < Resource
|
3
3
|
class WorksheetAssociationAlreadyRegisteredError < StandardError; end
|
4
|
+
class WorksheetNotFoundError < StandardError; end
|
4
5
|
|
5
6
|
set_resource_type GoogleDrive::Spreadsheet
|
6
7
|
|
7
8
|
def self.has_many(resource, worksheet_name:, class_name:)
|
8
9
|
register_worksheet_association(resource, worksheet_name: worksheet_name, class_name: class_name)
|
9
|
-
|
10
|
-
@worksheets ||= {}
|
11
|
-
@worksheets[resource] ||= Worksheet.new(
|
12
|
-
spreadsheet: self,
|
13
|
-
google_drive_resource: google_drive_resource.worksheet_by_title(worksheet_name),
|
14
|
-
type: Support.constantize(class_name)
|
15
|
-
)
|
16
|
-
end
|
10
|
+
create_worksheet_association(resource, worksheet_name: worksheet_name, class_name: class_name)
|
17
11
|
end
|
18
12
|
|
19
13
|
def self.register_worksheet_association(resource, worksheet_name:, class_name:)
|
@@ -27,6 +21,21 @@ module SheetsDB
|
|
27
21
|
}
|
28
22
|
end
|
29
23
|
|
24
|
+
def self.create_worksheet_association(resource, worksheet_name:, class_name:)
|
25
|
+
define_method(resource) do
|
26
|
+
@worksheets ||= {}
|
27
|
+
@worksheets[resource] ||= begin
|
28
|
+
google_drive_worksheet = google_drive_resource.worksheet_by_title(worksheet_name)
|
29
|
+
raise WorksheetNotFoundError, worksheet_name if google_drive_worksheet.nil?
|
30
|
+
Worksheet.new(
|
31
|
+
spreadsheet: self,
|
32
|
+
google_drive_resource: google_drive_worksheet,
|
33
|
+
type: Support.constantize(class_name)
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
30
39
|
def find_association_by_id(association_name, id)
|
31
40
|
find_associations_by_ids(association_name, [id]).first
|
32
41
|
end
|
@@ -43,4 +52,4 @@ module SheetsDB
|
|
43
52
|
send(association_name).select(&block)
|
44
53
|
end
|
45
54
|
end
|
46
|
-
end
|
55
|
+
end
|
data/lib/sheets_db/version.rb
CHANGED
data/lib/sheets_db/worksheet.rb
CHANGED
@@ -3,6 +3,8 @@ require_relative "worksheet/row"
|
|
3
3
|
|
4
4
|
module SheetsDB
|
5
5
|
class Worksheet
|
6
|
+
class ColumnNotFoundError < StandardError; end
|
7
|
+
|
6
8
|
include Enumerable
|
7
9
|
|
8
10
|
attr_reader :spreadsheet, :google_drive_resource, :type
|
@@ -43,9 +45,11 @@ module SheetsDB
|
|
43
45
|
|
44
46
|
def get_definition_and_column(attribute_name)
|
45
47
|
attribute_definition = attribute_definitions.fetch(attribute_name, {})
|
48
|
+
column_name = attribute_definition.fetch(:column_name, attribute_name.to_s)
|
49
|
+
raise ColumnNotFoundError, column_name if columns[column_name].nil?
|
46
50
|
[
|
47
51
|
attribute_definition,
|
48
|
-
columns[
|
52
|
+
columns[column_name]
|
49
53
|
]
|
50
54
|
end
|
51
55
|
|
@@ -135,4 +139,4 @@ module SheetsDB
|
|
135
139
|
converted_value
|
136
140
|
end
|
137
141
|
end
|
138
|
-
end
|
142
|
+
end
|
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.5.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: 2017-
|
11
|
+
date: 2017-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google_drive
|