Module: FatJam::ActsAsRevisable::Revision::ClassMethods

Defined in:
lib/acts_as_revisable/acts/revision.rb

Instance Method Summary collapse

Instance Method Details

#revisable_association_nameObject

Returns the name of the association acts_as_revision creates.



128
129
130
# File 'lib/acts_as_revisable/acts/revision.rb', line 128

def revisable_association_name #:nodoc:
  revisable_class_name.downcase
end

#revisable_classObject

Returns the actual Revisable class based on the #revisable_class_name.



113
114
115
# File 'lib/acts_as_revisable/acts/revision.rb', line 113

def revisable_class #:nodoc:
  self.revisable_revisable_class ||= revisable_class_name.constantize
end

#revisable_class_nameObject

Returns the revisable_class_name as configured in acts_as_revisable.



107
108
109
# File 'lib/acts_as_revisable/acts/revision.rb', line 107

def revisable_class_name #:nodoc:
  self.revisable_options.revisable_class_name || self.class_name.gsub(/Revision/, '')
end

#revision_classObject

Returns the revision_class which in this case is simply self.



118
119
120
# File 'lib/acts_as_revisable/acts/revision.rb', line 118

def revision_class #:nodoc:
  self
end

#revision_class_nameObject

:nodoc:



122
123
124
# File 'lib/acts_as_revisable/acts/revision.rb', line 122

def revision_class_name #:nodoc:
  self.name
end

#revision_cloned_associationsObject

Returns an array of the associations that should be cloned.



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/acts_as_revisable/acts/revision.rb', line 133

def revision_cloned_associations #:nodoc:
  clone_associations = self.revisable_options.clone_associations

  self.revisable_cloned_associations ||= if clone_associations.blank?
    []
  elsif clone_associations.eql? :all
    revisable_class.reflect_on_all_associations.map(&:name)
  elsif clone_associations.is_a? [].class
    clone_associations
  elsif clone_associations[:only]
    [clone_associations[:only]].flatten
  elsif clone_associations[:except]
    revisable_class.reflect_on_all_associations.map(&:name) - [clone_associations[:except]].flatten
  end        
end