Class: WikiContent

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

Overview

Since:

  • 0.5.0

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ WikiContent

Returns a new instance of WikiContent

Since:

  • 4.0.0



34
35
36
37
38
39
# File 'app/models/wiki_content.rb', line 34

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

Instance Method Details

#attachmentsObject

Since:

  • 1.0.0



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

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

#current_version?Boolean

Return true if the content is the current page content

Returns:

  • (Boolean)

Since:

  • 1.3.0



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

def current_version?
  true
end

#notified_usersObject

Since:

  • 3.0.0



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

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

#projectObject

Since:

  • 0.9.0



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

def project
  page.project
end

#recipientsObject

Returns the mail addresses of users that should be notified

Since:

  • 0.9.0



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

def recipients
  notified_users.collect(&:mail)
end

#revert_to!(version) ⇒ Object

Reverts the record to a previous version

Since:

  • 4.0.0



68
69
70
71
72
73
74
75
76
77
78
# File 'app/models/wiki_content.rb', line 68

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)

Since:

  • 0.9.0



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

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