Class: Version

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Property::Base, Property::Serialization::JSON, RubyLess, Versions::Auto, Versions::Destroy, Zena::Use::Dates::ModelMethods, Zena::Use::Workflow::VersionMethods
Defined in:
app/models/node.rb,
app/models/version.rb

Overview

This is an ugly fix related to the circular dependency between Node and Version

Direct Known Subclasses

TemplateVersion

Instance Attribute Summary

Attributes included from Zena::Use::Workflow::VersionMethods

#backup, #status_set, #stored_workflow

Instance Method Summary collapse

Methods included from Zena::Use::Workflow::VersionMethods

#clone_on_change?, #edited?, included, #should_clone?, #status=, #status_set?

Methods included from Zena::Use::Dates::ModelMethods

included

Methods included from Zena::Use::Dates::Common

#format_date

Instance Method Details

#authorObject



56
57
58
# File 'app/models/version.rb', line 56

def author
  user.node
end

#clonedObject

node_with_secure is defined in node.rb. It is an ugly fix related to the circular dependency between Node and Version



42
43
44
# File 'app/models/version.rb', line 42

def cloned
  set_defaults
end

#mark_for_destructionObject



60
61
62
63
# File 'app/models/version.rb', line 60

def mark_for_destruction
  super
  self.status = -1
end

#node_with_secureObject



1868
1869
1870
1871
1872
1873
1874
1875
# File 'app/models/node.rb', line 1868

def node_with_secure
  @node ||= begin
    if n = secure(Node) { node_without_secure }
      n.version = self
    end
    n
  end
end

#previous_numberObject



47
48
49
50
51
52
53
54
# File 'app/models/version.rb', line 47

def previous_number
  if node_id = self[:node_id]
    last_record = self.connection.select_one("SELECT number FROM #{self.class.table_name} WHERE node_id = '#{node[:id]}' ORDER BY number DESC LIMIT 1")
    (last_record || {})['number'].to_i
  else
    nil
  end
end