Class: Document

Inherits:
Object
  • Object
show all
Defined in:
lib/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, hash, colname) ⇒ Document

Creates new instance of document

  • Args :

    • client -> e.g. ExistAPI.new(“localhost:8080/exist/xmlrpc”, “admin”, “password”)

    • hash -> hash, name -> “name of the document”

    • colname -> name of the collection

  • Returns : -instance of document

  • Raises :

    • nothing

  • Example :

    • Document.new(api, hash, collection_path)



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/document.rb', line 26

def initialize(client, hash, colname)
  @client = client
  @path = colname + hash['name']
  @name = @path[/[^\/]+$/]
  #puts "filename #{@name}"
  @owner = hash['owner']
  @group = hash['group']
  @permissions = hash['permissions']
rescue  => e
  raise e  
end

Instance Attribute Details

#groupObject (readonly)

owner group of the document



10
11
12
# File 'lib/document.rb', line 10

def group
  @group
end

#nameObject (readonly)

name of the document



6
7
8
# File 'lib/document.rb', line 6

def name
  @name
end

#ownerObject (readonly)

owner of the document



8
9
10
# File 'lib/document.rb', line 8

def owner
  @owner
end

#pathObject (readonly)

path of the document



4
5
6
# File 'lib/document.rb', line 4

def path
  @path
end

#permissionsObject (readonly)

permissions of the document



12
13
14
# File 'lib/document.rb', line 12

def permissions
  @permissions
end

Instance Method Details

#contentObject

Returns content of document in db. Usually document is xml. Retrieves a document from the database.

  • Args :

    • none

  • Returns :

    • the result of call

  • Raises :

    • ExistException -> Failed to load content of Document



60
61
62
63
64
65
66
67
68
# File 'lib/document.rb', line 60

def content
  options = { "indent" => "yes", "encoding" => "UTF-8",
    "expand-xincludes" => "yes" }
  return @client.call("getDocument", @path, options)
rescue XMLRPC::FaultException => e
  raise e
rescue
  raise ExistException.new("Failed to load content of Document", 11), callers
end

#to_sObject

Returns string of document. That inclunde permissions, owner, group and name.

  • Args :

    • none

  • Returns : -string of collection

  • Raises :

    • nothing



47
48
49
# File 'lib/document.rb', line 47

def to_s
  return "#{@permissions} #{@owner} #{@group} #{@name}"
end