Module: ActiveMetadata::Stream

Defined in:
lib/active_metadata/stream.rb

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary collapse

Class Method Details

.by_group(group, *args) ⇒ Object

same as #stream_for but not filtered by field



9
10
11
12
13
# File 'lib/active_metadata/stream.rb', line 9

def by_group group, *args
  options = args.extract_options!
  order_by = options.delete(:order_by) || :created_at
  sort_stream(collect_stream_items_by_group(group, options), order_by)
end

.collect_stream_items_by_group(group, options) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/active_metadata/stream.rb', line 19

def collect_stream_items_by_group group, options
  res = []
  ActiveMetadata::CONFIG['streamables'].each do |model|
    res.concat "ActiveMetadata::#{model.to_s.capitalize}".to_class.send(:by_group, group.to_s, options).collect { |el| el }
  end
  res
end

.included(base) ⇒ Object



4
5
6
# File 'lib/active_metadata/stream.rb', line 4

def self.included(base)
  base.send :include, InstanceMethods
end

.sort_stream(stream, order_by) ⇒ Object



15
16
17
# File 'lib/active_metadata/stream.rb', line 15

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