mass_record 0.0.4.5 → 0.0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mass_record.rb +21 -3
- data/lib/mass_record/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: 81fb0c2269f13bcf50b6273f6cc47c696ff7794a
|
4
|
+
data.tar.gz: 68a589d4d3c8f1ed87fc1b31d4ed264123272ca2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10aaa87e98054d2b488e0d15e6eac082cfc035f0974dfea70264c645c211bac34a6464c3f9899d50c17a84368a5930a4da49cbf51417c9d7e66051bbd1c6be22
|
7
|
+
data.tar.gz: 6ac2d9b78f5bd3b64201ffa448d10e17130633baca923c8cce045133a8b1f461241689b830653318312a3081bb02ed9ee1aa8c79545c8c52fe212c5a3bb3bfc8
|
data/lib/mass_record.rb
CHANGED
@@ -53,15 +53,29 @@ module MassRecord
|
|
53
53
|
model = object.class
|
54
54
|
created_at = model.attribute_alias?("created_at") ? model.attribute_alias("created_at") : "created_at"
|
55
55
|
updated_at = model.attribute_alias?("updated_at") ? model.attribute_alias("updated_at") : "updated_at"
|
56
|
+
|
57
|
+
# narrow the attributes to just the relevant ones
|
56
58
|
keepers = object.attributes.select{|k,v| object.changed.include? k} if (operation.to_s == 'update' or !object.new_record?) and keep.blank?
|
57
59
|
keepers = object.attributes.select{|k,v| keep.map(&:to_s).include? k} unless keep.blank?
|
58
|
-
|
60
|
+
|
61
|
+
# also keep important fields primary key, and created and updated datestamps
|
62
|
+
unless keepers.blank?
|
63
|
+
keepers = keepers.merge(object.attributes.select{|k,v| (model.primary_key+[created_at,updated_at]).include? k}) if model.primary_key.is_a? Array
|
64
|
+
keepers = keepers.merge(object.attributes.select{|k,v| [model.primary_key,created_at,updated_at].include? k}) unless model.primary_key.is_a? Array
|
65
|
+
end
|
66
|
+
|
59
67
|
slimmed_objects << keepers
|
60
68
|
end
|
61
69
|
|
62
70
|
return slimmed_objects
|
63
71
|
end
|
64
72
|
|
73
|
+
def specify_save on: nil
|
74
|
+
return 'save' if on.blank?
|
75
|
+
return (on.new_record? ? 'insert' : 'update') if on.is_a? ActiveRecord::Base
|
76
|
+
return 'save'
|
77
|
+
end
|
78
|
+
|
65
79
|
# TODO: add logic to append the data if the filename already exists
|
66
80
|
# accepts an array of objects with the option to specify what rails operation to perform
|
67
81
|
def queue_for_quick_query object_array,
|
@@ -79,11 +93,15 @@ module MassRecord
|
|
79
93
|
class_array = object_array.collect{|x| x.class.name}
|
80
94
|
|
81
95
|
object_array = slim_data(object_array, keep:only, operation:operation) if operation.to_s == 'update' or !only.blank? or object_array.any?{|x| !x.new_record?}
|
82
|
-
|
96
|
+
|
83
97
|
queue = []
|
84
98
|
|
85
99
|
object_array.each_with_index do |object,i|
|
86
|
-
queue << {
|
100
|
+
queue << {
|
101
|
+
key[:table] => class_array[i],
|
102
|
+
key[:operation] => (operation.to_s.downcase == 'save') ? specify_save(on:object) : operation ,
|
103
|
+
key[:object] => object
|
104
|
+
} unless object.blank?
|
87
105
|
end
|
88
106
|
# begin
|
89
107
|
File.open(folder[:queued]+"/#{operation.to_s}_#{file_tag}.json",'w'){|f| f.write queue.to_json} unless queue.blank?
|
data/lib/mass_record/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module MassRecord
|
2
|
-
VERSION = "0.0.4.
|
2
|
+
VERSION = "0.0.4.6" # Fixed save updating trimming and save handling to account for multiple primary keys and a bug in assigning operations from save
|
3
3
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mass_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.4.
|
4
|
+
version: 0.0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Hanna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|