Class: ActiveCMIS::Collection

Inherits:
Object
  • Object
show all
Includes:
Internal::Caching, Enumerable
Defined in:
lib/active_cmis/collection.rb

Overview

A Collection represents an atom feed, and can be used to lazily load data through paging

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Internal::Caching

included

Constructor Details

#initialize(repository, url, first_page = nil, &map_entry) ⇒ Collection

Returns a new instance of Collection.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/active_cmis/collection.rb', line 15

def initialize(repository, url, first_page = nil, &map_entry)
  @repository = repository
  @url = URI.parse(url)

  @next = @url
  @elements = []
  @pages = []

  @map_entry = map_entry || Proc.new do |e|
    ActiveCMIS::Object.from_atom_entry(repository, e)
  end

  if first_page
    @next = first_page.xpath("at:feed/at:link[@rel = 'next']/@href", NS::COMBINED).first
    @pages[0] = first_page
  end
end

Instance Attribute Details

#repositoryRepository (readonly)

The repository that contains this feed

Returns:



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

def repository
  @repository
end

#urlURI (readonly)

The basic link that represents the beginning of this feed

Returns:

  • (URI)


13
14
15
# File 'lib/active_cmis/collection.rb', line 13

def url
  @url
end

Instance Method Details

#[](index, length = nil) ⇒ Object Also known as: slice



77
78
79
80
81
82
83
84
85
86
# File 'lib/active_cmis/collection.rb', line 77

def [](index, length = nil)
  if length
    index = sanitize_index(index)
    range_get(index, index + length - 1)
  elsif Range === index
    range_get(sanitize_index(index.begin), index.exclude_end? ? sanitize_index(index.end) - 1 : sanitize_index(index.end))
  else
    at(index)
  end
end

#at(index) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/active_cmis/collection.rb', line 63

def at(index)
  index = sanitize_index(index)
  if index < @elements.length
    @elements[index]
  elsif index > length
    nil
  else
    while @next && @elements.length < index
      receive_page
    end
    @elements[index]
  end
end

#destroy(options = {}) ⇒ Object

Attempts to delete the collection. This may not work on every collection, ActiveCMIS does not (yet) try to check this client side.

For folder collections 2 options are available, again no client side checking is done to see whether the collection can handle these options

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :unfileObjects (String)

    Parameter valid for items collection of folder “delete” (default): Delete all fileable objects “unfile”: unfile all fileable objects “deleteSingleFiled”: Delete all fileable objects, whose only parent folder is the current folder. Unfile all other objects from this folder

  • :continueOnFailure (Bool)

    default = false, if false abort on failure of single document/folder, else try to continue with deleting child folders/documents



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/active_cmis/collection.rb', line 153

def destroy(options = {})
  if options.empty?
    conn.delete(@url)
  else
    unfileObjects = options.delete(:unfileObjects)
    continueOnFailure = options.delete(:continueOnFailure)
    raise ArgumentError("Unknown parameters #{options.keys.join(', ')}") unless options.empty?


    # XXX: have less cumbersome code, more generic and more efficient code
    new_url = @url
    new_url = Internal::Utils.append_parameters(new_url, :unfileObjects => unfileObjects) unless unfileObjects.nil?
    new_url = Internal::Utils.append_parameters(new_url, :continueOnFailure => continueOnFailure) unless continueOnFailure.nil?

    # TODO: check that we can handle 200,202,204 responses correctly
    conn.delete(@url)
  end
end

#eachArray

Returns:

  • (Array)


99
100
101
# File 'lib/active_cmis/collection.rb', line 99

def each
  length.times { |i| yield self[i] }
end

#empty?Boolean

Returns:

  • (Boolean)


50
51
52
53
# File 'lib/active_cmis/collection.rb', line 50

def empty?
  at(0)
  @elements.empty?
end

#firstObject



89
90
91
# File 'lib/active_cmis/collection.rb', line 89

def first
  at(0)
end

#inspectString

Returns:

  • (String)


109
110
111
# File 'lib/active_cmis/collection.rb', line 109

def inspect
  "#<Collection %s>" % url
end

#lastObject

Gets all object and returns last



94
95
96
# File 'lib/active_cmis/collection.rb', line 94

def last
  at(-1)
end

#lengthInteger Also known as: size

Returns The length of the collection.

Returns:

  • (Integer)

    The length of the collection



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/active_cmis/collection.rb', line 34

def length
  receive_page
  if @length.nil?
    i = 1
    while @next
      receive_page
      i += 1
    end
    @elements.length
  else
    @length
  end
end

#reloadvoid

This method returns an undefined value.



134
135
136
137
138
139
# File 'lib/active_cmis/collection.rb', line 134

def reload
  @pages = []
  @elements = []
  @next = @url
  __reload
end

#reverseArray

Returns:

  • (Array)


129
130
131
# File 'lib/active_cmis/collection.rb', line 129

def reverse
  to_a.reverse
end

#reverse_eachArray

Returns:

  • (Array)


104
105
106
# File 'lib/active_cmis/collection.rb', line 104

def reverse_each
  (length - 1).downto(0) { |i| yield self[i] }
end

#sortArray

Returns:

  • (Array)


124
125
126
# File 'lib/active_cmis/collection.rb', line 124

def sort
  to_a.sort
end

#to_aArray

Returns:

  • (Array)


56
57
58
59
60
61
# File 'lib/active_cmis/collection.rb', line 56

def to_a
  while @next
    receive_page
  end
  @elements
end

#to_sString

Returns:

  • (String)


114
115
116
# File 'lib/active_cmis/collection.rb', line 114

def to_s
  to_a.to_s
end

#uniqArray

Returns:

  • (Array)


119
120
121
# File 'lib/active_cmis/collection.rb', line 119

def uniq
  to_a.uniq
end