Module: FatJam::ActsAsRevisable::Common::ClassMethods
- Defined in:
- lib/acts_as_revisable/acts/common.rb
Instance Method Summary collapse
- #disable_revisable_scope(*args) ⇒ Object
-
#instantiate_with_revisable(record) ⇒ Object
acts_as_revisable’s override for instantiate so we can return the appropriate type of model based on whether or not the record is the current record.
-
#revisable_should_clone_column?(col) ⇒ Boolean
Returns true if the revision should clone the given column.
Instance Method Details
#disable_revisable_scope(*args) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/acts_as_revisable/acts/common.rb', line 167 def disable_revisable_scope(*args) args.each do |a| class_eval " def \#{a.to_s}_with_open_scope(*args, &block)\n assoc = self.class.reflect_on_association(\#{a.inspect})\n models = [self.class]\n \n if [:has_many, :has_one].member? assoc.macro\n models << (assoc.options[:class_name] ? assoc.options[:class_name] : \#{a.inspect}.to_s.singularize.camelize).constantize\n end\n \n begin\n models.each {|m| m.scoped_model_enabled = false}\n if associated = \#{a.to_s}_without_open_scope(*args, &block)\n associated.reload\n end\n ensure\n models.each {|m| m.scoped_model_enabled = true}\n end\n end\n EOT\n alias_method_chain a, :open_scope\n end\nend\n" |
#instantiate_with_revisable(record) ⇒ Object
acts_as_revisable’s override for instantiate so we can return the appropriate type of model based on whether or not the record is the current record.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/acts_as_revisable/acts/common.rb', line 201 def instantiate_with_revisable(record) #:nodoc: is_current = columns_hash["revisable_is_current"].type_cast( record["revisable_is_current"]) if (is_current && self == self.revisable_class) || (!is_current && self == self.revision_class) return instantiate_without_revisable(record) end object = if is_current self.revisable_class else self.revision_class end.allocate object.instance_variable_set("@attributes", record) object.instance_variable_set("@attributes_cache", Hash.new) if object.respond_to_without_attributes?(:after_find) object.send(:callback, :after_find) end if object.respond_to_without_attributes?(:after_initialize) object.send(:callback, :after_initialize) end object end |
#revisable_should_clone_column?(col) ⇒ Boolean
Returns true if the revision should clone the given column.
193 194 195 196 |
# File 'lib/acts_as_revisable/acts/common.rb', line 193 def revisable_should_clone_column?(col) #:nodoc: return false if (REVISABLE_SYSTEM_COLUMNS + REVISABLE_UNREVISABLE_COLUMNS).member? col true end |