Class: Confluence::Page

Inherits:
RemoteDataObject show all
Defined in:
lib/confluence/page.rb

Overview

Exposes a vaguely ActiveRecord-like interface for dealing with Confluence::Pages in Confluence.

Constant Summary collapse

DEFAULT_SPACE =
"encore"

Instance Attribute Summary

Attributes inherited from RemoteDataObject

#attributes, #confluence, #encore

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RemoteDataObject

#==, #[], #[]=, #as_boolean, #as_datetime, #as_int, #as_string, confluence, connector, connector=, #destroy, encore, find, #id, #method_missing, #reload, #save

Constructor Details

#initialize(data_object = nil) ⇒ Page

Returns a new instance of Page.



25
26
27
28
# File 'lib/confluence/page.rb', line 25

def initialize(data_object = nil)
  super
  #self.creator = self.confluence_user unless self.include? :creator
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Confluence::RemoteDataObject

Class Method Details

.find_by_name(name, space = DEFAULT_SPACE) ⇒ Object

class methods ###########################################################



102
103
104
# File 'lib/confluence/page.rb', line 102

def self.find_by_name(name, space = DEFAULT_SPACE)
  find_by_title(name, space)    
end

.find_by_title(title, space = DEFAULT_SPACE) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/confluence/page.rb', line 106

def self.find_by_title(title, space = DEFAULT_SPACE)
  begin
    r = confluence.getPage(space, title)
  rescue Confluence::RemoteException => e
    # FIXME: dangerous to be checking based on error string like this...
    if e.message =~ /does not exist/
      return nil
    else
      raise e
    end
  end
  self.new(r)
end

Instance Method Details

#before_saveObject

callbacks ###############################################################



94
95
96
# File 'lib/confluence/page.rb', line 94

def before_save
  raise "Cannot save this page because it has no title and/or space." unless self.title and self.space
end

#content=(new_content) ⇒ Object



38
39
40
41
42
43
# File 'lib/confluence/page.rb', line 38

def content=(new_content)
  # make sure metadata doesn't get overwritten
   = self..entries if self.content
  super
  self..merge!  if 
end

#edit_groupObject



66
67
68
69
70
71
72
73
# File 'lib/confluence/page.rb', line 66

def edit_group
  perm = get_permissions
  return nil if perm.nil? or perm.empty?
  perm.each do |p|
    return p['lockedBy'] if p['lockType'] == 'Edit'
  end
  return nil
end

#edit_group=(group) ⇒ Object



62
63
64
# File 'lib/confluence/page.rb', line 62

def edit_group=(group)
  encore.setPageEditGroup(self.title, group)
end

#get_permissionsObject



88
89
90
# File 'lib/confluence/page.rb', line 88

def get_permissions
  confluence.getPagePermissions(self.id.to_s)
end

#load_from_object(data_object) ⇒ Object



45
46
47
48
# File 'lib/confluence/page.rb', line 45

def load_from_object(data_object)
  super
  self.modifier = self.confluence_username unless self.attributes.include? :modifier
end

#metadataObject



50
51
52
# File 'lib/confluence/page.rb', line 50

def 
  Confluence::.new(self)
end

#nameObject



34
35
36
# File 'lib/confluence/page.rb', line 34

def name
  self.title
end

#name=(new_name) ⇒ Object



30
31
32
# File 'lib/confluence/page.rb', line 30

def name=(new_name)
  self.title = new_name
end

#parentObject



54
55
56
# File 'lib/confluence/page.rb', line 54

def parent
  self.class.find(self.parentId)
end

#to_sObject



58
59
60
# File 'lib/confluence/page.rb', line 58

def to_s
  self.title
end

#view_groupObject



79
80
81
82
83
84
85
86
# File 'lib/confluence/page.rb', line 79

def view_group
  perm = get_permissions
  return nil if perm.nil? or perm.empty?
  perm.each do |p|
    return p['lockedBy'] if p['lockType'] == 'View'
  end
  return nil
end

#view_group=(group) ⇒ Object



75
76
77
# File 'lib/confluence/page.rb', line 75

def view_group=(group)
  encore.setPageViewGroup(self.title, group)
end