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)


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

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)


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

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.



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

def revisable_class #:nodoc:
  self
end

#revisable_watch_columnsObject

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



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

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.



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

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.



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

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.



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

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


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

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