Skip to content
This repository
Browse code

fix stack level too deep error when accessing attributes in combinati…

…on with inheritance - evil hack
  • Loading branch information...
commit 33bf9532b6ba70353de7837383f2b0332b9de716 1 parent 494dc15
Alexander Lang authored
9 lib/couch_potato/persistence/dirty_attributes.rb
@@ -6,7 +6,6 @@ module DirtyAttributes
6 6 def self.included(base) #:nodoc:
7 7 base.send :include, ActiveModel::Dirty
8 8 base.class_eval do
9   - extend ClassMethods
10 9 after_save :reset_dirty_attributes
11 10 end
12 11 end
@@ -43,14 +42,6 @@ def clone_attribute(value)
43 42 value.clone
44 43 end
45 44 end
46   -
47   - module ClassMethods
48   - def property(name, *args)
49   - undefine_attribute_methods
50   - define_attribute_methods property_names + [name]
51   - super name, *args
52   - end
53   - end
54 45 end
55 46 end
56 47 end
12 lib/couch_potato/persistence/properties.rb
@@ -70,7 +70,19 @@ def property_names
70 70 # property :publisher, :type => Publisher
71 71 # end
72 72 def property(name, options = {})
  73 + undefine_attribute_methods
  74 + define_attribute_methods property_names + [name]
73 75 properties << SimpleProperty.new(self, name, options)
  76 + remove_attribute_accessors_from_activesupport_module
  77 + end
  78 +
  79 + def remove_attribute_accessors_from_activesupport_module
  80 + active_support_module = ancestors[1..-1].find{|m| m.name.nil? && (property_names - m.instance_methods).empty?}
  81 + if active_support_module
  82 + property_names.each do |name|
  83 + active_support_module.send :remove_method, name if active_support_module.instance_methods.include?(name)
  84 + end
  85 + end
74 86 end
75 87 end
76 88 end

0 comments on commit 33bf953

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