Class: WikiContent

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/wiki_content.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ WikiContent

Returns a new instance of WikiContent.



39
40
41
42
43
44
# File 'app/models/wiki_content.rb', line 39

def initialize(*args)
  super
  if new_record?
    self.version = 1
  end
end

Instance Method Details

#attachmentsObject



54
55
56
# File 'app/models/wiki_content.rb', line 54

def attachments
  page.nil? ? [] : page.attachments
end

#current_version?Boolean

Return true if the content is the current page content

Returns:

  • (Boolean)


68
69
70
# File 'app/models/wiki_content.rb', line 68

def current_version?
  true
end

#notified_usersObject



58
59
60
# File 'app/models/wiki_content.rb', line 58

def notified_users
  project.notified_users.reject {|user| !visible?(user)}
end

#projectObject



50
51
52
# File 'app/models/wiki_content.rb', line 50

def project
  page.project
end

#recipientsObject

Returns the mail addresses of users that should be notified



63
64
65
# File 'app/models/wiki_content.rb', line 63

def recipients
  notified_users.collect(&:mail)
end

#revert_to!(version) ⇒ Object

Reverts the record to a previous version



73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/wiki_content.rb', line 73

def revert_to!(version)
  if version.wiki_content_id == id
    update_columns(
      :author_id => version.author_id,
      :text => version.text,
      :comments => version.comments,
      :version => version.version,
      :updated_on => version.updated_on
    ) && reload
  end
end

#visible?(user = User.current) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'app/models/wiki_content.rb', line 46

def visible?(user=User.current)
  page.visible?(user)
end