activerecord_data_importer 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/activerecord_data_importer.rb +10 -8
- data/lib/activerecord_data_importer/version.rb +1 -1
- 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: 9ad392f5c9ba5ebd15c3344e2eed15f5295d3178
|
4
|
+
data.tar.gz: 37a7251dd85dda331ff59ecff58741931d0054bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32c1eeba66d812b17bb917731bf08a50376b2e61067b57e91b2eea839ac97075e559767af6771cd5018b61f7a80e1f9ba05da803a614e1d5fc20a7a124cdde54
|
7
|
+
data.tar.gz: 01f188c6eb48318e5f6bae1b4091f8478e7e38e79d0543e0cb752bc9171bdd1405fb842beb4413f69f78a3adeb469ec7e31b782c8076b819082db7e3c442ce89
|
@@ -74,6 +74,8 @@ module ActiverecordDataImporter
|
|
74
74
|
self_attributes, another_attributes = self.class.divide_attributes row_data
|
75
75
|
origin_updated = self.update_origin self_attributes, latest_version
|
76
76
|
return origin_updated if another_attributes.blank?
|
77
|
+
relation_attributes = self.class.divide_relation_key another_attributes
|
78
|
+
return origin_updated if relation_attributes.blank?
|
77
79
|
relation_updated = self.update_relation another_attributes
|
78
80
|
if (!origin_updated && relation_updated)
|
79
81
|
self.update_with_version latest_version
|
@@ -91,15 +93,15 @@ module ActiverecordDataImporter
|
|
91
93
|
true
|
92
94
|
end
|
93
95
|
|
94
|
-
def update_relation(
|
96
|
+
def update_relation(all_relation_attributes)
|
95
97
|
latest_version = self.class.get_latest_version
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
98
|
+
all_relation_attributes.select do |key, value|
|
99
|
+
case value
|
100
|
+
when Hash
|
101
|
+
relation_instance = self.try(key) || self.try("build_#{key}")
|
102
|
+
relation_instance.update_row_data value, latest_version
|
103
|
+
when Array
|
104
|
+
relation_instances = self.try(key).to_a
|
103
105
|
updated_flag = false
|
104
106
|
value.each_with_index do |relation_attributes, i|
|
105
107
|
relation_instance = relation_instances[i] || self.try(key).build
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord_data_importer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ukayare
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'ActiverecordDataImporter is enable to load and import file (format is
|
14
14
|
csv, json) for ActiveRecord''s model. For example, when you must use and import
|