Class: CMIS::Object

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/cmis/object.rb

Direct Known Subclasses

Document, Folder, Item, Policy, Relationship

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#cmis_properties, #initialize_properties, #method_missing, #respond_to?, #with_change_token

Constructor Details

#initialize(raw, repository) ⇒ Object

Returns a new instance of Object


10
11
12
13
14
15
16
17
18
# File 'lib/cmis/object.rb', line 10

def initialize(raw, repository)
  initialize_properties(raw)
  cmis_properties %w( cmis:objectId cmis:baseTypeId cmis:objectTypeId
                      cmis:secondaryObjectTypeIds cmis:name cmis:description
                      cmis:createdBy cmis:creationDate cmis:lastModifiedBy
                      cmis:lastModificationDate cmis:changeToken )

  @repository = repository
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CMIS::Helpers

Instance Attribute Details

#propertiesObject (readonly)

Returns the value of attribute properties


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

def properties
  @properties
end

#repositoryObject (readonly)

Returns the value of attribute repository


7
8
9
# File 'lib/cmis/object.rb', line 7

def repository
  @repository
end

Instance Method Details

#acls(opts = {}) ⇒ Object


102
103
104
105
106
# File 'lib/cmis/object.rb', line 102

def acls(opts = {})
  server.execute!({ cmisselector: 'acl',
                    repositoryId: repository.id,
                    objectId: cmis_object_id }, opts)
end

#add_aces(aces, opts = {}) ⇒ Object


108
109
110
111
112
113
# File 'lib/cmis/object.rb', line 108

def add_aces(aces, opts = {})
  server.execute!({ cmisaction: 'applyACL',
                    repositoryId: repository.id,
                    objectId: cmis_object_id,
                    addACEs: aces }, opts)
end

#allowable_actions(opts = {}) ⇒ Object


60
61
62
63
64
# File 'lib/cmis/object.rb', line 60

def allowable_actions(opts = {})
  server.execute!({ cmisselector: 'allowableActions',
                    repositoryId: repository.id,
                    objectId: cmis_object_id }, opts)
end

#delete(opts = {}) ⇒ Object


24
25
26
27
28
29
# File 'lib/cmis/object.rb', line 24

def delete(opts = {})
  server.execute!({ cmisaction: 'delete',
                    repositoryId: repository.id,
                    objectId: cmis_object_id,
                    allVersions: true }, opts)
end

#delete_with_relationships(opts = {}) ⇒ Object


31
32
33
34
35
36
# File 'lib/cmis/object.rb', line 31

def delete_with_relationships(opts = {})
  relationships.each_relationship(limit: :all) do |rel|
    rel.delete(opts)
  end
  delete(opts)
end

#detached?Boolean

Returns:

  • (Boolean)

122
123
124
# File 'lib/cmis/object.rb', line 122

def detached?
  cmis_object_id.nil?
end

#inspectObject


130
131
132
# File 'lib/cmis/object.rb', line 130

def inspect
  "#{self.class}[#{cmis_object_id}] @ #{repository.inspect}"
end

#move(target_folder, opts = {}) ⇒ Object


88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/cmis/object.rb', line 88

def move(target_folder, opts = {})
  object_parents = parents

  unless object_parents.size == 1
    raise 'Cannot move object because it is not in exactly one folder'
  end

  server.execute!({ cmisaction: 'move',
                    repositoryId: repository.id,
                    objectId: cmis_object_id,
                    targetFolderId: target_folder.cmis_object_id,
                    sourceFolderId: object_parents.first.cmis_object_id }, opts)
end

#object_type(opts = {}) ⇒ Object


20
21
22
# File 'lib/cmis/object.rb', line 20

def object_type(opts = {})
  repository.type(object_type_id, opts)
end

#parents(opts = {}) ⇒ Object


52
53
54
55
56
57
58
# File 'lib/cmis/object.rb', line 52

def parents(opts = {})
  result = server.execute!({ cmisselector: 'parents',
                             repositoryId: repository.id,
                             objectId: cmis_object_id }, opts)

  result.map { |o| ObjectFactory.create(o['object'], repository) }
end

#policies(opts = {}) ⇒ Object


70
71
72
73
74
75
76
# File 'lib/cmis/object.rb', line 70

def policies(opts = {})
  result = server.execute!({ cmisselector: 'policies',
                             repositoryId: repository.id,
                             objectId: cmis_object_id }, opts)

  result.map { |r| Policy.new(r, repository) }
end

#refresh(opts = {}) ⇒ Object


126
127
128
# File 'lib/cmis/object.rb', line 126

def refresh(opts = {})
  detached? ? self : repository.object(cmis_object_id, opts)
end

#relationships(opts = {}) ⇒ Object


66
67
68
# File 'lib/cmis/object.rb', line 66

def relationships(opts = {})
  Relationships.new(self, opts)
end

#remove_aces(aces, opts = {}) ⇒ Object


115
116
117
118
119
120
# File 'lib/cmis/object.rb', line 115

def remove_aces(aces, opts = {})
  server.execute!({ cmisaction: 'applyACL',
                    repositoryId: repository.id,
                    objectId: cmis_object_id,
                    removeACEs: aces }, opts)
end

#unfile(folder = nil, opts = {}) ⇒ Object

By default removes from all folders


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

def unfile(folder = nil, opts = {})
  params = { repositoryId: repository.id,
             cmisaction: 'removeObjectFromFolder',
             objectId: cmis_object_id }
  params.update!(folderId: folder.cmis_object_id) if folder

  server.execute!(params, opts)
end

#update_properties(props, opts = {}) ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cmis/object.rb', line 38

def update_properties(props, opts = {})
  if detached?
    properties.merge!(props)
  else
    with_change_token do
      server.execute!({ cmisaction: 'update',
                        repositoryId: repository.id,
                        objectId: cmis_object_id,
                        properties: props,
                        changeToken: change_token }, opts)
    end
  end
end