Class: ActiveCMIS::Collection
- Inherits:
-
Object
- Object
- ActiveCMIS::Collection
- 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
-
#repository ⇒ Repository
readonly
The repository that contains this feed.
-
#url ⇒ URI
readonly
The basic link that represents the beginning of this feed.
Instance Method Summary collapse
- #[](index, length = nil) ⇒ Object (also: #slice)
- #at(index) ⇒ Object
- #each ⇒ Array
- #empty? ⇒ Boolean
- #first ⇒ Object
-
#initialize(repository, url, first_page = nil, &map_entry) ⇒ Collection
constructor
A new instance of Collection.
- #inspect ⇒ String
-
#last ⇒ Object
Gets all object and returns last.
-
#length ⇒ Integer
(also: #size)
The length of the collection.
- #reload ⇒ void
- #reverse ⇒ Array
- #reverse_each ⇒ Array
- #sort ⇒ Array
- #to_a ⇒ Array
- #to_s ⇒ String
- #uniq ⇒ Array
Methods included from Internal::Caching
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
#repository ⇒ Repository (readonly)
The repository that contains this feed
10 11 12 |
# File 'lib/active_cmis/collection.rb', line 10 def repository @repository end |
#url ⇒ URI (readonly)
The basic link that represents the beginning of this feed
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 |
#each ⇒ Array
99 100 101 |
# File 'lib/active_cmis/collection.rb', line 99 def each length.times { |i| yield self[i] } end |
#empty? ⇒ Boolean
50 51 52 53 |
# File 'lib/active_cmis/collection.rb', line 50 def empty? at(0) @elements.empty? end |
#first ⇒ Object
89 90 91 |
# File 'lib/active_cmis/collection.rb', line 89 def first at(0) end |
#inspect ⇒ String
109 110 111 |
# File 'lib/active_cmis/collection.rb', line 109 def inspect "#<Collection %s>" % url end |
#last ⇒ Object
Gets all object and returns last
94 95 96 |
# File 'lib/active_cmis/collection.rb', line 94 def last at(-1) end |
#length ⇒ Integer Also known as: size
Returns 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 |
#reload ⇒ void
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 |
#reverse ⇒ Array
129 130 131 |
# File 'lib/active_cmis/collection.rb', line 129 def reverse to_a.reverse end |
#reverse_each ⇒ Array
104 105 106 |
# File 'lib/active_cmis/collection.rb', line 104 def reverse_each (length - 1).downto(0) { |i| yield self[i] } end |
#sort ⇒ Array
124 125 126 |
# File 'lib/active_cmis/collection.rb', line 124 def sort to_a.sort end |
#to_a ⇒ 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_s ⇒ String
114 115 116 |
# File 'lib/active_cmis/collection.rb', line 114 def to_s to_a.to_s end |
#uniq ⇒ Array
119 120 121 |
# File 'lib/active_cmis/collection.rb', line 119 def uniq to_a.uniq end |