Sha256: 9164918dd929dfba67ef7d34972500171ba82ec4fb7fd7a1659c55820c7f312e

Contents?: true

Size: 577 Bytes

Versions: 2

Compression:

Stored size: 577 Bytes

Contents

module ActiveMetadata::Streamable

  def stream_for(field, order_by = :created_at)
    sort_stream(collect_stream_data(field), order_by)
  end

  private
  def sort_stream stream, order_by
    stream.sort{ |a,b| b.send(order_by) <=> a.send(order_by) }
  end

  def collect_stream_data field
    res = []
    ActiveMetadata::CONFIG['streamables'].each do |model|
      res.concat self.send(stream_collect_method(model.to_s),field).collect { |el| el }
    end
    res
  end

  def stream_collect_method model
    model.to_s == 'note' ? 'notes_for' : 'attachments_for'
  end


end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_metadata-0.6.9 lib/active_metadata/streamable.rb
active_metadata-0.6.7 lib/active_metadata/streamable.rb