Module: CouchPotato::Persistence::DeepDirtyAttributes::ClassMethods

Defined in:
lib/couch_potato/persistence/deep_dirty_attributes.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#deep_trackable_type?(type) ⇒ Boolean

Returns:

  • (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_propertiesObject



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_namesObject



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

Returns:

  • (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

Returns:

  • (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, options = {})
  super
  if deep_trackable_type?(options[:type])
    index = properties.find_index {|p| p.name == name}
    properties.list[index] = DeepTrackedProperty.new(self, name, options)
    remove_attribute_dirty_methods_from_activesupport_module
  end
end

#remove_attribute_dirty_methods_from_activesupport_moduleObject



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

Returns:

  • (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