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
164 165 166 |
# File 'lib/couch_potato/persistence/deep_dirty_attributes.rb', line 164 def deep_trackable_type?(type) type && type.is_a?(Array) || doc_type?(type) end |
#deep_tracked_properties ⇒ Object
168 169 170 171 172 |
# File 'lib/couch_potato/persistence/deep_dirty_attributes.rb', line 168 def deep_tracked_properties properties.select do |property| property.is_a? DeepTrackedProperty end end |
#deep_tracked_property_names ⇒ Object
174 175 176 |
# File 'lib/couch_potato/persistence/deep_dirty_attributes.rb', line 174 def deep_tracked_property_names deep_tracked_properties.map(&:name) end |
#doc_array_type?(type) ⇒ Boolean
150 151 152 |
# File 'lib/couch_potato/persistence/deep_dirty_attributes.rb', line 150 def doc_array_type?(type) type && type.is_a?(Array) && doc_type?(type[0]) end |
#doc_type?(type) ⇒ Boolean
158 159 160 161 162 |
# File 'lib/couch_potato/persistence/deep_dirty_attributes.rb', line 158 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, ) end remove_attribute_dirty_methods_from_activesupport_module end |
#remove_attribute_dirty_methods_from_activesupport_module ⇒ Object
140 141 142 143 144 145 146 147 148 |
# 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"]}.map(&:to_sym) activesupport_modules = ancestors.select {|m| m.name.nil? && (methods - m.instance_methods).empty?} activesupport_modules.each do |mod| methods.each do |method| mod.send :remove_method, method if mod.instance_methods.include?(method) end end end |
#simple_array_type?(type) ⇒ Boolean
154 155 156 |
# File 'lib/couch_potato/persistence/deep_dirty_attributes.rb', line 154 def simple_array_type?(type) type && type.is_a?(Array) && !doc_type?(type[0]) end |