mass_record 0.0.4.4 → 0.0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mass_record.rb +24 -4
- 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: d054cc552db3f8d9fe3ab38b89a12b619ff09b40
|
4
|
+
data.tar.gz: 4ccaaf474db13bffc0961fc6ad7e734bd2416966
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfa78f96994e965feb82fba8eff9fbf07305d45dcf8d568765efd4985c7a49455bf01445a0c9b42b8caf07e7de55427d38ffcd213e931e288180afcd2959569b
|
7
|
+
data.tar.gz: f5219ad0d9399a3912548a46a3cc7a909243ab566632d1f42220c31cd6cacd285d220b5ae8bb1b8b3f0eceeab10a4357480321fdf0cb829ec8ebd0e01e3f0b37
|
data/lib/mass_record.rb
CHANGED
@@ -45,6 +45,23 @@ module MassRecord
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
def slim_data object_array, keep:[], operation: :save
|
49
|
+
return object_array if keep.blank? unless operation.to_s == 'update' or object_array.any?{|x| !x.new_record?}
|
50
|
+
slimmed_objects = []
|
51
|
+
|
52
|
+
object_array.each do |object|
|
53
|
+
model = object.class
|
54
|
+
created_at = model.attribute_alias?("created_at") ? model.attribute_alias("created_at") : "created_at"
|
55
|
+
updated_at = model.attribute_alias?("updated_at") ? model.attribute_alias("updated_at") : "updated_at"
|
56
|
+
keepers = object.attributes.select{|k,v| object.changed.include? k} if (operation.to_s == 'update' or !object.new_record?) and keep.blank?
|
57
|
+
keepers = object.attributes.select{|k,v| keep.map(&:to_s).include? k} unless keep.blank?
|
58
|
+
keepers = keepers.merge(object.attributes.select{|k,v| [model.primary_key,created_at,updated_at].include? k}) unless keepers.blank?
|
59
|
+
slimmed_objects << keepers
|
60
|
+
end
|
61
|
+
|
62
|
+
return slimmed_objects
|
63
|
+
end
|
64
|
+
|
48
65
|
# TODO: add logic to append the data if the filename already exists
|
49
66
|
# accepts an array of objects with the option to specify what rails operation to perform
|
50
67
|
def queue_for_quick_query object_array,
|
@@ -55,18 +72,21 @@ module MassRecord
|
|
55
72
|
table: "table",
|
56
73
|
operation: "operation",
|
57
74
|
object: "object"
|
58
|
-
}
|
75
|
+
},only:[]
|
59
76
|
|
60
77
|
object_array = [object_array] unless object_array.is_a? Array
|
61
78
|
return false if object_array.blank?
|
79
|
+
class_array = object_array.collect{|x| x.class.name}
|
62
80
|
|
81
|
+
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
|
+
|
63
83
|
queue = []
|
64
84
|
|
65
|
-
object_array.
|
66
|
-
queue << {key[:table] =>
|
85
|
+
object_array.each_with_index do |object,i|
|
86
|
+
queue << {key[:table] => class_array[i], key[:operation] => (operation.to_s.downcase == 'save' and object.new_record?) ? 'insert' : 'update' , key[:object] => object} unless object.blank?
|
67
87
|
end
|
68
88
|
# begin
|
69
|
-
File.open(folder[:queued]+"/#{operation.to_s}_#{file_tag}.json",'w'){|f| f.write queue.to_json}
|
89
|
+
File.open(folder[:queued]+"/#{operation.to_s}_#{file_tag}.json",'w'){|f| f.write queue.to_json} unless queue.blank?
|
70
90
|
# rescue Exception => e
|
71
91
|
# pp "#{e.message}\n#{e.backtrace[0..5].pretty_inspect}".red
|
72
92
|
# end
|
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.5" # added intelligent handling of updates and saves, determines save vs. update before creating queued file (without needing queries) and filters out all fields not involved in the update
|
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.5
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|