Module: FatJam::ActsAsRevisable::Revisable::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#find_with_revisable(*args) ⇒ Object

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

Example

find(:all, :with_revisions => true)


424
425
426
427
428
429
430
431
432
433
434
# File 'lib/acts_as_revisable/acts/revisable.rb', line 424

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

  if options && options.delete(:with_revisions)
    without_model_scope do
      find_without_revisable(*args)
    end
  else
    find_without_revisable(*args)
  end
end

#find_with_revisions(*args) ⇒ Object

Equivalent to:

find(..., :with_revisions => true)


438
439
440
441
442
# File 'lib/acts_as_revisable/acts/revisable.rb', line 438

def find_with_revisions(*args)
  args << {} if args.grep(Hash).blank?
  args.grep(Hash).first.update({:with_revisions => true})
  find_with_revisable(*args)
end

#revisable_classObject

Returns the revisable_class which in this case is simply self.



457
458
459
# File 'lib/acts_as_revisable/acts/revisable.rb', line 457

def revisable_class #:nodoc:
  self
end

#revisable_watch_columnsObject

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



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

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.



452
453
454
# File 'lib/acts_as_revisable/acts/revisable.rb', line 452

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

#revision_class_nameObject

Returns the revision_class_name as configured in acts_as_revisable.



446
447
448
# File 'lib/acts_as_revisable/acts/revisable.rb', line 446

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

#revisions_association_nameObject

Returns the name of the association acts_as_revisable creates.



463
464
465
# File 'lib/acts_as_revisable/acts/revisable.rb', line 463

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

#with_scope_with_revisable(*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


406
407
408
409
410
411
412
413
414
415
416
# File 'lib/acts_as_revisable/acts/revisable.rb', line 406

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

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