Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/restfulie/server/core_ext/array.rb

Overview

Introspective methods to assist in the conversion of collections in other formats.

Instance Method Summary collapse

Instance Method Details

#published_at(field = :published_at) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/restfulie/server/core_ext/array.rb', line 27

def published_at(field = :published_at)
  min = min_by{|o| o.send(field)}
  if min
    min.send(field)
  else
    Time.now
  end
end

#updated_at(field = :updated_at) ⇒ Object

Return max update date for items in collection, for it uses the updated_at of items.

Example:

Find max updated at in ActiveRecord objects

albums = Albums.find(:all)
albums.updated_at

Using a custom field to check the max date

albums = Albums.find(:all)
albums.updated_at(:created_at)


18
19
20
21
22
23
24
25
# File 'lib/restfulie/server/core_ext/array.rb', line 18

def updated_at(field = :updated_at)
  max = max_by{|o| o.send(field)}
  if max
    max.send(field)
  else
    Time.now
  end
end