Module: WithoutScope::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.



125
126
127
# File 'lib/acts_as_revisable/acts/revision.rb', line 125

def revisable_association_name #:nodoc:
  revisable_class_name.underscore
end

#revisable_classObject

Returns the actual Revisable class based on the #revisable_class_name.



110
111
112
# File 'lib/acts_as_revisable/acts/revision.rb', line 110

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

#revisable_class_nameObject

Returns the revisable_class_name as configured in acts_as_revisable.



104
105
106
# File 'lib/acts_as_revisable/acts/revision.rb', line 104

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

#revision_classObject

Returns the revision_class which in this case is simply self.



115
116
117
# File 'lib/acts_as_revisable/acts/revision.rb', line 115

def revision_class #:nodoc:
  self
end

#revision_class_nameObject

:nodoc:



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

def revision_class_name #:nodoc:
  self.name
end

#revision_cloned_associationsObject

Returns an array of the associations that should be cloned.



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

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