Module: WithoutScope::ActsAsRevisable::Revisable::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#find(*args) ⇒ Object

acts_as_revisable’s override for find that allows for including revisions in the find.

Example

find(:all, :with_revisions => true)


434
435
436
437
438
439
440
441
442
443
444
# File 'lib/acts_as_revisable/acts/revisable.rb', line 434

def find(*args) #:nodoc:
  options = args.grep(Hash).first

  if options && options.delete(:with_revisions)
    with_exclusive_scope do
      super(*args)
    end
  else
    super(*args)
  end
end

#revisable_classObject

Returns the revisable_class which in this case is simply self.



459
460
461
# File 'lib/acts_as_revisable/acts/revisable.rb', line 459

def revisable_class #:nodoc:
  self
end

#revisable_watch_columnsObject

Returns an Array of the columns that are watched for changes.



470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/acts_as_revisable/acts/revisable.rb', line 470

def revisable_watch_columns #:nodoc:
  return self.revisable_columns unless self.revisable_columns.blank?
  return self.revisable_columns ||= [] if self.revisable_options.except == :all
  return self.revisable_columns ||= [self.revisable_options.only].flatten.map(&:to_s).map(&:downcase) unless self.revisable_options.only.blank?
            
  except = [self.revisable_options.except].flatten || []
  except += REVISABLE_SYSTEM_COLUMNS
  except += REVISABLE_UNREVISABLE_COLUMNS
  except.uniq!

  self.revisable_columns ||= (column_names - except.map(&:to_s)).flatten.map(&:downcase)
end

#revision_classObject

Returns the actual Revision class based on the #revision_class_name.



454
455
456
# File 'lib/acts_as_revisable/acts/revisable.rb', line 454

def revision_class #:nodoc:
  self.revisable_revision_class ||= self.revision_class_name.constantize
end

#revision_class_nameObject

Returns the revision_class_name as configured in acts_as_revisable.



448
449
450
# File 'lib/acts_as_revisable/acts/revisable.rb', line 448

def revision_class_name #:nodoc:
  self.revisable_options.revision_class_name || "#{self.name}Revision"
end

#revisions_association_nameObject

Returns the name of the association acts_as_revisable creates.



465
466
467
# File 'lib/acts_as_revisable/acts/revisable.rb', line 465

def revisions_association_name #:nodoc:
  revision_class_name.pluralize.underscore
end

#with_scope(*args, &block) ⇒ Object

acts_as_revisable’s override for with_scope that allows for including revisions in the scope.

Example

with_scope(:with_revisions => true) do
  ...
end


416
417
418
419
420
421
422
423
424
425
426
# File 'lib/acts_as_revisable/acts/revisable.rb', line 416

def with_scope(*args, &block) #:nodoc:
  options = (args.grep(Hash).first || {})[:find]

  if options && options.delete(:with_revisions)
    with_exclusive_scope do
      super(*args, &block)
    end
  else
    super(*args, &block)
  end
end