Module: CouchPotato::Persistence::DeepDirtyAttributes::ClassMethods
- Defined in:
- lib/couch_potato/persistence/deep_dirty_attributes.rb
Overview
:nodoc:
Instance Method Summary collapse
- #deep_trackable_type?(type) ⇒ Boolean
- #deep_tracked_properties ⇒ Object
- #deep_tracked_property_names ⇒ Object
- #doc_array_type?(type) ⇒ Boolean
- #doc_type?(type) ⇒ Boolean
- #property(name, options = {}) ⇒ Object
- #remove_attribute_dirty_methods_from_activesupport_module ⇒ Object
- #simple_array_type?(type) ⇒ Boolean
Instance Method Details
#deep_trackable_type?(type) ⇒ Boolean
166 167 168 |
# File 'lib/couch_potato/persistence/deep_dirty_attributes.rb', line 166 def deep_trackable_type?(type) type && type.is_a?(Array) || doc_type?(type) end |
#deep_tracked_properties ⇒ Object
170 171 172 173 174 |
# File 'lib/couch_potato/persistence/deep_dirty_attributes.rb', line 170 def deep_tracked_properties properties.select do |property| property.is_a? DeepTrackedProperty end end |
#deep_tracked_property_names ⇒ Object
176 177 178 |
# File 'lib/couch_potato/persistence/deep_dirty_attributes.rb', line 176 def deep_tracked_property_names deep_tracked_properties.map(&:name) end |
#doc_array_type?(type) ⇒ Boolean
152 153 154 |
# File 'lib/couch_potato/persistence/deep_dirty_attributes.rb', line 152 def doc_array_type?(type) type && type.is_a?(Array) && doc_type?(type[0]) end |
#doc_type?(type) ⇒ Boolean
160 161 162 163 164 |
# File 'lib/couch_potato/persistence/deep_dirty_attributes.rb', line 160 def doc_type?(type) type && type.respond_to?(:included_modules) && type.included_modules.include?(DirtyAttributes) end |
#property(name, options = {}) ⇒ Object
131 132 133 134 135 136 137 138 |
# File 'lib/couch_potato/persistence/deep_dirty_attributes.rb', line 131 def property(name, = {}) super if deep_trackable_type?([:type]) index = properties.find_index {|p| p.name == name} properties.list[index] = DeepTrackedProperty.new(self, name, ) remove_attribute_dirty_methods_from_activesupport_module end end |
#remove_attribute_dirty_methods_from_activesupport_module ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/couch_potato/persistence/deep_dirty_attributes.rb', line 140 def remove_attribute_dirty_methods_from_activesupport_module methods = deep_tracked_property_names.flat_map {|n| [:"#{n}_changed?", :"#{n}_change", :"#{n}_was"]} active_support_module = send(:generated_attribute_methods) if active_support_module methods.each do |method| if active_support_module.instance_methods.include?(method) active_support_module.send :remove_method, method end end end end |
#simple_array_type?(type) ⇒ Boolean
156 157 158 |
# File 'lib/couch_potato/persistence/deep_dirty_attributes.rb', line 156 def simple_array_type?(type) type && type.is_a?(Array) && !doc_type?(type[0]) end |