Converter 1.1.1.0 → 1.1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/Converter.rb +11 -1
  2. metadata +2 -2
data/lib/Converter.rb CHANGED
@@ -23,6 +23,11 @@ module Converter
23
23
  # @param [Any Class] target the result type
24
24
  # @return target with new values
25
25
  def self.copy source, target, hash = {}
26
+ # copy of nil is always nil!!
27
+ if !source
28
+ return false
29
+ end
30
+
26
31
  # Check if the object has already been converted (Circular pointing)
27
32
  if(converted_object = hash[source])
28
33
  return converted_object
@@ -83,7 +88,7 @@ module Converter
83
88
  if source.class == target.class
84
89
  source
85
90
  else
86
- raise ArgumentError.new "Unable to select from two Convertable objects"
91
+ raise ArgumentError.new "Unable to select between two Convertable objects. classes: #{source.class}, #{target.class}"
87
92
  end
88
93
  elsif source.class.included_modules.include? Converter
89
94
  source
@@ -95,11 +100,16 @@ module Converter
95
100
  end
96
101
 
97
102
  def self.convert_one_attribute source, target, conversion_metadata, is_source_convertable, hash
103
+ # Get attribute names from conversion metadata
98
104
  source_attribute_name = is_source_convertable ? conversion_metadata.convertable_attribute_name : conversion_metadata.poro_attribute_name
99
105
  target_attribute_name = is_source_convertable ? conversion_metadata.poro_attribute_name : conversion_metadata.convertable_attribute_name
106
+
107
+ # Get attribute values
100
108
  source_attribute_value = source.send(source_attribute_name)
101
109
  target_attribute_value = target.send(target_attribute_name)
102
110
  target_attribute_name = target_attribute_name.to_s.concat('=').to_sym
111
+
112
+ # Get converter lambda (to convert between the two values)
103
113
  convert_block = conversion_metadata.get_converter(source_attribute_value, target_attribute_value, is_source_convertable)
104
114
 
105
115
  # Convert from one type to another (by default doesn't do anything)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1.0
4
+ version: 1.1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-21 00:00:00.000000000 Z
12
+ date: 2012-07-22 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Add attr_converter to maps attributes to another object, and this allows
15
15
  you to copy, convert and clone between them automatically