Skip to content
Browse files

handle setting of Date and NilClass values in from_hash()

  • Loading branch information...
1 parent a97ab6e commit 0764cabbff6f578769ab7f7004153fa4e84cc908 @robmckinnon robmckinnon committed Mar 30, 2009
Showing with 7 additions and 3 deletions.
  1. +2 −0 CHANGELOG
  2. +5 −3 lib/morph.rb
View
2 CHANGELOG
@@ -1,3 +1,5 @@
+v0.2.6. handle more types of value types in from_hash()
+
v0.2.5. camelize names for classes in from_hash()
v0.2.4. from_hash() creates classes in Morph namespace and handles arrays of hashes
View
8 lib/morph.rb
@@ -1,7 +1,7 @@
require 'activesupport'
module Morph
- VERSION = "0.2.5"
+ VERSION = "0.2.6"
class << self
def generate_migrations object, options={}
@@ -92,14 +92,16 @@ def add_to_object object, attributes, namespace
attributes.each do |name, value|
attribute = name.gsub(':',' ').underscore
case value
- when String
+ when String, Date
object.morph(attribute, value)
when Array
object.morph(attribute.pluralize, objects_from_array(value, name, namespace))
when Hash
object.morph(attribute, object_from_hash(value, name, namespace))
+ when NilClass
+ object.morph(attribute, nil)
else
- raise "cannot handle adding value of class: #{value.class.name}"
+ raise "cannot handle adding #{name} value of class: #{value.class.name}"
end
end
object

0 comments on commit 0764cab

Please sign in to comment.
Something went wrong with that request. Please try again.