Module: Cms::Behaviors::Versioning::MacroMethods

Defined in:
lib/cms/behaviors/versioning.rb

Instance Method Summary collapse

Instance Method Details

#is_versioned(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cms/behaviors/versioning.rb', line 11

def is_versioned(options={})
  @is_versioned = true

  @version_foreign_key = (options[:version_foreign_key] || "#{name.underscore}_id").to_s
  @version_table_name = (options[:version_table_name] || "#{table_name.singularize}_versions").to_s

  extend ClassMethods
  include InstanceMethods

  has_many :versions, :class_name  => version_class_name, :foreign_key => version_foreign_key

  before_validation_on_create :initialize_version

  attr_accessor :revert_to_version

  #Define the version class
  const_set("Version", Class.new(ActiveRecord::Base)).class_eval do 
    class << self; attr_accessor :versioned_class end

    def versioned_class
      self.class.versioned_class
    end
    def versioned_object_id
      send("#{versioned_class.name.underscore}_id")
    end
    def versioned_object
      send(versioned_class.name.underscore.to_sym)
    end                 
  end unless self.const_defined?("Version")

  version_class.versioned_class = self

  version_class.belongs_to(name.underscore.to_sym, :foreign_key => version_foreign_key)

  version_class.is_userstamped if userstamped?

end

#versioned?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/cms/behaviors/versioning.rb', line 8

def versioned?
  !!@is_versioned
end