Class: Dolly::Collection

Inherits:
Array
  • Object
show all
Defined in:
lib/dolly/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rows: [], options: {}) ⇒ Collection

Returns a new instance of Collection.



7
8
9
10
11
12
# File 'lib/dolly/collection.rb', line 7

def initialize(rows: [], options: {})
  @options = options
  #TODO: We should raise an exception if one of the
  #      requested documents is missing
  super rows[:rows].map(&collect_docs).compact
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/dolly/collection.rb', line 5

def options
  @options
end

Instance Method Details

#first_or_all(forced_first = false) ⇒ Object



14
15
16
17
# File 'lib/dolly/collection.rb', line 14

def first_or_all(forced_first = false)
  return self if forced_first
  single? ? first : self
end

#single?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/dolly/collection.rb', line 19

def single?
  size <= 1
end