Permalink
Browse files

Initialize class attributes on inclusion.

Methods like #delocalizing? may be called before #delocalize and then fail with
errors like "undefined method `any?' for nil:NilClass" (happens e.g. with Rails
3.2.3 and Mongoid).
  • Loading branch information...
1 parent 6f3ea96 commit 81d94e14947cd08a3b48d1b9f88e915b689a07bf @noniq noniq committed Apr 5, 2012
Showing with 2 additions and 3 deletions.
  1. +2 −3 lib/delocalize/delocalizable.rb
View
5 lib/delocalize/delocalizable.rb
@@ -7,13 +7,12 @@ module Delocalizable
included do
class_attribute :delocalizable_fields
class_attribute :delocalize_conversions
+ self.delocalize_conversions = {}
+ self.delocalizable_fields = []
end
module ClassMethods
def delocalize(conversions = {})
- self.delocalize_conversions ||= {}
- self.delocalizable_fields ||= []
-
conversions.each do |field, type|
delocalizable_fields << field.to_sym unless delocalizable_fields.include?(field.to_sym)
delocalize_conversions[field.to_sym] = type.to_sym

0 comments on commit 81d94e1

Please sign in to comment.