From 2f3116d1991dc5d1006f0b26d9feff7e6a657aa1 Mon Sep 17 00:00:00 2001 From: Yaniv Ran Date: Wed, 15 Jun 2016 11:42:36 -0700 Subject: [PATCH 1/3] Add support for serialized and type casted fields Changed Attributes to attributes_before_type_cast to maintain the original values, as well as getting the correct value for serialized fields. --- lib/seed_dump/dump_methods.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/seed_dump/dump_methods.rb b/lib/seed_dump/dump_methods.rb index 25236a1..4794f0b 100644 --- a/lib/seed_dump/dump_methods.rb +++ b/lib/seed_dump/dump_methods.rb @@ -21,8 +21,9 @@ def dump_record(record, options) # We select only string attribute names to avoid conflict # with the composite_primary_keys gem (it returns composite # primary key attribute names as hashes). - record.attributes.select {|key| key.is_a?(String) }.each do |attribute, value| - attribute_strings << dump_attribute_new(attribute, value, options) unless options[:exclude].include?(attribute.to_sym) + record.attributes_before_type_cast.select {|key| key.is_a?(String) }.each do |attribute, value| + new_value = record.instance_variable_get("@attributes")[attribute].try(:serialized_value) ? record.instance_variable_get("@attributes")[attribute].serialized_value : value + attribute_strings << dump_attribute_new(attribute, new_value, options) unless options[:exclude].include?(attribute.to_sym) end open_character, close_character = options[:import] ? ['[', ']'] : ['{', '}'] From c9a79fcc0e7269ada9cc294381e821a804c7d6bd Mon Sep 17 00:00:00 2001 From: Yaniv Ran Date: Thu, 16 Jun 2016 09:51:15 -0700 Subject: [PATCH 2/3] add an option to enable or disable serialization. --- lib/seed_dump/dump_methods.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/seed_dump/dump_methods.rb b/lib/seed_dump/dump_methods.rb index 4794f0b..ddeba92 100644 --- a/lib/seed_dump/dump_methods.rb +++ b/lib/seed_dump/dump_methods.rb @@ -22,7 +22,10 @@ def dump_record(record, options) # with the composite_primary_keys gem (it returns composite # primary key attribute names as hashes). record.attributes_before_type_cast.select {|key| key.is_a?(String) }.each do |attribute, value| - new_value = record.instance_variable_get("@attributes")[attribute].try(:serialized_value) ? record.instance_variable_get("@attributes")[attribute].serialized_value : value + new_value = value + if (options[:serialized]=="false") + new_value = record.instance_variable_get("@attributes")[attribute].try(:serialized_value) ? record.instance_variable_get("@attributes")[attribute].serialized_value : value + end attribute_strings << dump_attribute_new(attribute, new_value, options) unless options[:exclude].include?(attribute.to_sym) end From ccfcd52ed840b70bfb20021443f43449dc077fa2 Mon Sep 17 00:00:00 2001 From: Yaniv Ran Date: Mon, 20 Jun 2016 09:01:22 -0700 Subject: [PATCH 3/3] Update dump_methods.rb --- lib/seed_dump/dump_methods.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/seed_dump/dump_methods.rb b/lib/seed_dump/dump_methods.rb index ddeba92..3b64819 100644 --- a/lib/seed_dump/dump_methods.rb +++ b/lib/seed_dump/dump_methods.rb @@ -23,7 +23,7 @@ def dump_record(record, options) # primary key attribute names as hashes). record.attributes_before_type_cast.select {|key| key.is_a?(String) }.each do |attribute, value| new_value = value - if (options[:serialized]=="false") + if (options[:serialized]==false) new_value = record.instance_variable_get("@attributes")[attribute].try(:serialized_value) ? record.instance_variable_get("@attributes")[attribute].serialized_value : value end attribute_strings << dump_attribute_new(attribute, new_value, options) unless options[:exclude].include?(attribute.to_sym)