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

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

Instance Method Summary collapse

Instance Method Details

#is_versioned(options = {}) ⇒ Object


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/cms/behaviors/versioning.rb', line 75

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

  @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
  after_save :update_latest_version

  before_validation :initialize_version
  before_save :build_new_version
  attr_accessor :skip_callbacks
  attr_accessible :version_comment

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

    include VersionRecord
    self.mass_assignment_sanitizer = Cms::IgnoreSanitizer.new

    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.demodulize.underscore.to_sym, :foreign_key => version_foreign_key, :class_name => name)

  version_class.is_userstamped if userstamped?

end

#versioned?Boolean


71
72
73
# File 'lib/cms/behaviors/versioning.rb', line 71

def versioned?
  !!@is_versioned
end