Class: Trestle::Resource::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/trestle/resource/collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(admin, options = {}) ⇒ Collection

Returns a new instance of Collection.


7
8
9
# File 'lib/trestle/resource/collection.rb', line 7

def initialize(admin, options={})
  @admin, @options = admin, options
end

Instance Method Details

#decorate?Boolean

Returns:

  • (Boolean)

37
38
39
# File 'lib/trestle/resource/collection.rb', line 37

def decorate?
  @options[:decorate] != false
end

#finalize?Boolean

Returns:

  • (Boolean)

33
34
35
# File 'lib/trestle/resource/collection.rb', line 33

def finalize?
  @options[:finalize] != false
end

#paginate?Boolean

Returns:

  • (Boolean)

29
30
31
# File 'lib/trestle/resource/collection.rb', line 29

def paginate?
  @options[:paginate] != false
end

#prepare(params) ⇒ Object


11
12
13
14
15
16
17
18
19
# File 'lib/trestle/resource/collection.rb', line 11

def prepare(params)
  collection = collection(params)
  collection = apply_scopes(collection, params)  if scope?
  collection = apply_sorting(collection, params) if sort?
  collection = paginate(collection, params)      if paginate?
  collection = finalize_collection(collection)   if finalize?
  collection = decorate_collection(collection)   if decorate?
  collection
end

#scope?Boolean

Returns:

  • (Boolean)

21
22
23
# File 'lib/trestle/resource/collection.rb', line 21

def scope?
  @options[:scope] != false
end

#sort?Boolean

Returns:

  • (Boolean)

25
26
27
# File 'lib/trestle/resource/collection.rb', line 25

def sort?
  @options[:sort] != false
end