activerecord_to_google_spreadsheet 0.1.0 → 0.2.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22f9450fd8340fc122d6b589940ab8d6ec1cfc3c
|
4
|
+
data.tar.gz: c5a987e700d04f5f15aede36034ccdf19c6509d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 561c4bfbf7c9b4b314be477432b6baddbf3fb491bf23a9f7d3187b1a4b296e654de3ec33db814c8c8dcc5bc4b5f2ba03a9f7fdc903dc45dbc4811a23a66bf2f3
|
7
|
+
data.tar.gz: cda0f6191727bb43059a529e11c4b6486bd395c512090418709985c9bad950e45558b2bfb2c1bbf50ac83a89a1872b2bfbba73f4f9639bd60a7c9c12a5e855fe
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "activerecord_to_google_spreadsheet/version"
|
2
2
|
require "activerecord_to_google_spreadsheet/utils"
|
3
|
+
require "activerecord_to_google_spreadsheet/converter"
|
3
4
|
require "google_drive"
|
4
5
|
module ActiveRecordToGoogleSpreadsheet
|
5
6
|
extend Utils
|
@@ -113,55 +114,18 @@ module ActiveRecordToGoogleSpreadsheet
|
|
113
114
|
return auth_url.to_s
|
114
115
|
end
|
115
116
|
|
116
|
-
module ActiveRecordBaseConverter
|
117
|
-
def to_google_spreadsheet
|
118
|
-
puts '****************************base test************'
|
119
|
-
clazz = self.model_name.name.capitalize.singularize.camelize.to_s.constantize
|
120
|
-
puts clazz.column_names
|
121
|
-
clazz.column_names.each do |name|
|
122
|
-
puts self[name]
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def from_google_spreadsheet
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
module ActiveRecordRelationConverter
|
131
|
-
include Utils
|
132
|
-
extend Utils
|
133
|
-
def to_google_spreadsheet(session, spreadsheet_key, name: self.table_name, worksheet_title: false, row_offset: 1)
|
134
|
-
spreadsheet = session.spreadsheet_by_key(spreadsheet_key)
|
135
|
-
ws = get_worksheet_by_name(spreadsheet, name)
|
136
|
-
|
137
|
-
if worksheet_title
|
138
|
-
self.column_names.each_with_index do |name, column_index|
|
139
|
-
ws[row_offset, column_index+1] = name
|
140
|
-
end
|
141
|
-
row_offset += 1
|
142
|
-
end
|
143
|
-
|
144
|
-
self.each_with_index do |item, index|
|
145
|
-
self.column_names.each_with_index do |name, column_index|
|
146
|
-
ws[index + row_offset, column_index + 1] = item[name]
|
147
|
-
end
|
148
|
-
end
|
149
|
-
ws.save
|
150
|
-
ws.reload
|
151
|
-
end
|
152
|
-
|
153
|
-
def from_google_spreadsheet
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
117
|
class ActiveRecord::Base
|
158
|
-
include ActiveRecordBaseConverter
|
118
|
+
include Converter::ActiveRecordBaseConverter
|
159
119
|
end
|
160
120
|
|
161
121
|
class ActiveRecord::Relation
|
162
|
-
include ActiveRecordRelationConverter
|
122
|
+
include Converter::ActiveRecordRelationConverter
|
163
123
|
end
|
164
124
|
|
125
|
+
# class Array
|
126
|
+
# include Converter::ArrayConverter
|
127
|
+
# end
|
128
|
+
|
165
129
|
def self.each_tables(session, spreadsheet_key)
|
166
130
|
spreadsheet = session.spreadsheet_by_key(spreadsheet_key)
|
167
131
|
info = get_db_info
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module ActiveRecordToGoogleSpreadsheet
|
2
|
+
module Converter
|
3
|
+
module ActiveRecordBaseConverter
|
4
|
+
include Utils
|
5
|
+
extend Utils
|
6
|
+
|
7
|
+
def to_google_spreadsheet(session, spreadsheet_key, name: self.model_name.name, worksheet_title: false, row_offset: 1)
|
8
|
+
|
9
|
+
clazz = self.model_name.name.capitalize.singularize.camelize.to_s.constantize
|
10
|
+
spreadsheet = session.spreadsheet_by_key(spreadsheet_key)
|
11
|
+
ws = get_worksheet_by_name(spreadsheet, name)
|
12
|
+
|
13
|
+
clazz.column_names.each_with_index.each do |name, column_index|
|
14
|
+
if worksheet_title
|
15
|
+
ws[row_offset, column_index+1] = name
|
16
|
+
ws[row_offset + 1, column_index + 1] = self[name]
|
17
|
+
else
|
18
|
+
ws[row_offset, column_index + 1] = self[name]
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
ws.save
|
23
|
+
ws.reload
|
24
|
+
end
|
25
|
+
|
26
|
+
def from_google_spreadsheet
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module ActiveRecordRelationConverter
|
31
|
+
include Utils
|
32
|
+
extend Utils
|
33
|
+
|
34
|
+
def to_google_spreadsheet(session, spreadsheet_key, name: self.table_name, worksheet_title: false, row_offset: 1)
|
35
|
+
spreadsheet = session.spreadsheet_by_key(spreadsheet_key)
|
36
|
+
ws = get_worksheet_by_name(spreadsheet, name)
|
37
|
+
|
38
|
+
if worksheet_title
|
39
|
+
self.column_names.each_with_index do |name, column_index|
|
40
|
+
ws[row_offset, column_index+1] = name
|
41
|
+
end
|
42
|
+
row_offset += 1
|
43
|
+
end
|
44
|
+
|
45
|
+
self.each_with_index do |item, index|
|
46
|
+
self.column_names.each_with_index do |name, column_index|
|
47
|
+
ws[index + row_offset, column_index + 1] = item[name]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
ws.save
|
51
|
+
ws.reload
|
52
|
+
end
|
53
|
+
|
54
|
+
def from_google_spreadsheet
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
module ArrayConverter
|
59
|
+
include Utils
|
60
|
+
extend Utils
|
61
|
+
|
62
|
+
def to_google_spreadsheet(session, spreadsheet_key, name, worksheet_title: false, row_offset: 1)
|
63
|
+
if self.length > 0
|
64
|
+
spreadsheet = session.spreadsheet_by_key(spreadsheet_key)
|
65
|
+
ws = get_worksheet_by_name(spreadsheet, name)
|
66
|
+
|
67
|
+
self.each_with_index do |item, index|
|
68
|
+
if index == 0 && item.is_a?(ActiveRecord::Base) && worksheet_title
|
69
|
+
item.to_google_spreadsheet(session, spreadsheet_key, name: name, worksheet_title: true, row_offset: row_offset + index)
|
70
|
+
row_offset += 1
|
71
|
+
elsif item.is_a? ActiveRecord::Base
|
72
|
+
item.to_google_spreadsheet(session, spreadsheet_key, name: name, row_offset: row_offset + index)
|
73
|
+
elsif item.is_a? Array
|
74
|
+
item.each_with_index do |array_item, array_index|
|
75
|
+
ws[index + row_offset, array_index + 1] = item[name] = array_item
|
76
|
+
end
|
77
|
+
|
78
|
+
else
|
79
|
+
ws[index + row_offset, 1] = val
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord_to_google_spreadsheet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Otis Chen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- bin/console
|
56
56
|
- bin/setup
|
57
57
|
- lib/activerecord_to_google_spreadsheet.rb
|
58
|
+
- lib/activerecord_to_google_spreadsheet/converter.rb
|
58
59
|
- lib/activerecord_to_google_spreadsheet/utils.rb
|
59
60
|
- lib/activerecord_to_google_spreadsheet/version.rb
|
60
61
|
homepage: https://github.com/kkooff2000/activerecord_to_google_spreadsheet
|