summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordB <dblock@dblock.org>2014-08-23 20:25:18 -0400
committerdB <dblock@dblock.org>2014-08-23 20:34:02 -0400
commit70f1f897d7381572209fc955842909669c249c15 (patch)
treee0dca3bb2126a3a7c136ffb65d14a9c6041a35e0 /lib
parent32d5b0488145982bb0f35920ddb4f879e121d4d5 (diff)
downloadhashie-70f1f897d7381572209fc955842909669c249c15.tar.gz
Fix #69: regression, multiple property assignments in Trash.
Heavily inspired from https://github.com/intridea/hashie/commit/9a389853c98af876a80d1914acc0e24c4084ffb3.
Diffstat (limited to 'lib')
-rw-r--r--lib/hashie/trash.rb18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/hashie/trash.rb b/lib/hashie/trash.rb
index 204b0d7..7aff6f8 100644
--- a/lib/hashie/trash.rb
+++ b/lib/hashie/trash.rb
@@ -26,11 +26,13 @@ module Hashie
fail ArgumentError, "Property name (#{property_name}) and :from option must not be the same"
end
- translations[options[:from]] = property_name
+ translations[options[:from]] ||= {}
+ translations[options[:from]][property_name] = options[:with] || options[:transform_with]
define_method "#{options[:from]}=" do |val|
- with = options[:with] || options[:transform_with]
- self[property_name] = with.respond_to?(:call) ? with.call(val) : val
+ self.class.translations[options[:from]].each do |name, with|
+ self[name] = with.respond_to?(:call) ? with.call(val) : val
+ end
end
else
if options[:transform_with].respond_to? :call
@@ -82,7 +84,15 @@ module Hashie
private
def self.inverse_translations
- @inverse_translations ||= Hash[translations.map(&:reverse)]
+ @inverse_translations ||= begin
+ h = {}
+ translations.each do |(property_name, property_translations)|
+ property_translations.keys.each do |k|
+ h[k] = property_name
+ end
+ end
+ h
+ end
end
# Raises an NoMethodError if the property doesn't exist