Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added assigning nil support to has_details plugin

  • Loading branch information...
commit ace6bf9886926729be342dea096a8eef329f9acf 1 parent 4922107
@tarmo tarmo authored erkki committed
Showing with 6 additions and 2 deletions.
  1. +6 −2 lib/has_details.rb
View
8 lib/has_details.rb
@@ -42,7 +42,7 @@ def has_details(options = {})
configuration.each do |f,t|
exception_code = t.is_a?(Array) ? "raise \"Assigned value must be one of #{t.inspect}\" unless #{t.inspect}.include?(val)" : \
- "raise \"Assigned value must be a #{t.inspect}\" unless val.is_a?(#{t.inspect})"
+ "raise \"Assigned value must be a #{t.inspect}\" unless val.nil? || val.is_a?(#{t.inspect})"
class_eval <<-EOV
def #{f}
@@ -54,7 +54,11 @@ def #{f}=(val)
#{exception_code}
self.details ||= {}
- self.details[:#{f}] = val
+ if val.nil?
+ self.details.delete(:#{f})
+ else
+ self.details[:#{f}] = val
+ end
end
EOV
end
Please sign in to comment.
Something went wrong with that request. Please try again.