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

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

Instance Method Summary collapse

Instance Method Details

#is_versioned(options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/cms/behaviors/versioning.rb', line 33

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 :initialize_version
  before_save :build_new_version
  attr_accessor :skip_callbacks

  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)


29
30
31
# File 'lib/cms/behaviors/versioning.rb', line 29

def versioned?
  !!@is_versioned
end