Sha256: 80a1df5f8cbc88996849f764d3275fc862d780316dbee584aa21ef6bca5ffad7

Contents?: true

Size: 748 Bytes

Versions: 8

Compression:

Stored size: 748 Bytes

Contents

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

  # 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)
  #
  def updated_at(field = :updated_at)
    max = max_by{|o| o.send(field)}
    if max
      max.send(field)
    else
      Time.now
    end
  end

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

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
restfulie-nosqlite-1.0.4 lib/restfulie/server/core_ext/array.rb
restfulie-1.1.1 lib/restfulie/server/core_ext/array.rb
restfulie-1.1.0 lib/restfulie/server/core_ext/array.rb
restfulie-nosqlite-1.0.3 lib/restfulie/server/core_ext/array.rb
restfulie-1.0.3 lib/restfulie/server/core_ext/array.rb
restfulie-1.0.0 lib/restfulie/server/core_ext/array.rb
restfulie-1.0.0.beta5 lib/restfulie/server/core_ext/array.rb
restfulie-1.0.0.beta4 lib/restfulie/server/core_ext/array.rb