Module: ActiveMetadata::Stream::InstanceMethods

Defined in:
lib/active_metadata/stream.rb

Instance Method Summary collapse

Instance Method Details

#collect_stream_data(field) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/active_metadata/stream.rb', line 36

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

#stream_collect_method(model) ⇒ Object



44
45
46
# File 'lib/active_metadata/stream.rb', line 44

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

#stream_for(field, order_by = :created_at) ⇒ Object

return the streamables items by field in an ordered array ActiveMetadata::CONFIG defines what models will be retrieved



32
33
34
# File 'lib/active_metadata/stream.rb', line 32

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