activeresource-google_spreadsheets 0.1.6 → 0.1.7
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: 2c5bcdb99d1d9f0f957e277e28b1ad099c29fd8e
|
4
|
+
data.tar.gz: 0a95a492fa7435a2c50e0b10ed041c07e9f1a351
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da3e9aaa716cc7a9a40f1f9955f0d539679e60b7980f37ac8db00fe41be2860bd2aa7eddd41d8e9d381cf7fd80083da0d735a0d8ffa545ff7fd0ea2796057f93
|
7
|
+
data.tar.gz: c84889b8eae583ac50d6b1d5e8390bdbbcf8a01308302bb9b0624ba27aef59dee017892aa2af093f48ca54b72104d4d0df0474f8b87edf14733e4501a116e42f
|
@@ -24,9 +24,13 @@ module GoogleSpreadsheets
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def where(condition_hash)
|
27
|
-
condition_hash.inject(self.to_a) do |array, (attr, value)|
|
27
|
+
conditioned_elements = condition_hash.inject(self.to_a) do |array, (attr, value)|
|
28
28
|
array.find_all{|element| element.send(attr) == value }
|
29
29
|
end
|
30
|
+
self.class.new(conditioned_elements).tap do |collection|
|
31
|
+
collection.resource_class = self.resource_class
|
32
|
+
collection.original_params = self.original_params
|
33
|
+
end
|
30
34
|
end
|
31
35
|
end
|
32
36
|
end
|
@@ -18,12 +18,13 @@ module GoogleSpreadsheets
|
|
18
18
|
# sync_with :user_rows, spreadsheet_id: 'xxxx',
|
19
19
|
# worksheet_title: 'users'
|
20
20
|
# after_commit :sync_user_row
|
21
|
-
def sync_with(rows_name, options)
|
21
|
+
def sync_with(rows_name, scope = nil, options)
|
22
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
|
26
26
|
class_name = opts.delete(:class_name) || rows_name.to_s.classify
|
27
|
+
opts[:scope] = scope
|
27
28
|
synchronizer = Synchronizer.new(self, class_name.safe_constantize, spreadsheet_id, worksheet_title, opts)
|
28
29
|
self.synchronizers = self.synchronizers.merge(rows_name => synchronizer) # not share parent class attrs
|
29
30
|
|
@@ -60,19 +61,26 @@ module GoogleSpreadsheets
|
|
60
61
|
|
61
62
|
def all_rows
|
62
63
|
reflections = worksheet.class.reflections.values.find_all{|ref| ref.is_a?(LinkRelations::LinkRelationReflection) }
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
collection =
|
65
|
+
if reflection = reflections.find{|ref| ref.klass == row_class }
|
66
|
+
worksheet.send(reflection.name)
|
67
|
+
elsif reflection = reflections.find{|ref| ref.options[:rel] == REL_NAME_ROW }
|
68
|
+
worksheet.send(reflection.name, as: row_class.to_s)
|
69
|
+
else
|
70
|
+
raise "Reflection for #{row_class.to_s} not found."
|
71
|
+
end
|
72
|
+
if @options[:scope]
|
73
|
+
collection = collection.instance_exec(&@options[:scope])
|
69
74
|
end
|
75
|
+
collection
|
70
76
|
end
|
71
77
|
|
72
|
-
def sync_with_rows
|
78
|
+
def sync_with_rows(scope = nil)
|
73
79
|
reset
|
74
80
|
records_to_save = {}
|
75
|
-
|
81
|
+
rows = all_rows
|
82
|
+
rows = rows.instance_exec(&scope) if scope
|
83
|
+
rows.each do |row|
|
76
84
|
if row.id.present?
|
77
85
|
record_id = row.id.to_i
|
78
86
|
record = records_to_save[record_id] || record_class.find_or_initialize_by(id: record_id)
|
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
|
+
version: 0.1.7
|
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: 2017-
|
12
|
+
date: 2017-04-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activeresource
|
@@ -140,3 +140,4 @@ signing_key:
|
|
140
140
|
specification_version: 4
|
141
141
|
summary: Google Spreadsheets accessor with ActiveResource
|
142
142
|
test_files: []
|
143
|
+
has_rdoc:
|