Class: FeedAggregatedComponent

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/feed_aggregated_component.rb

Class Method Summary collapse

Class Method Details

.created_recently(feed, reference, secondary_reference = nil) ⇒ Object



10
11
12
# File 'app/models/feed_aggregated_component.rb', line 10

def self.created_recently(feed, reference, secondary_reference = nil)
  time_scope('created', Time.now - 5.minutes, feed, reference, secondary_reference)
end

.created_today(feed, reference, secondary_reference = nil) ⇒ Object



6
7
8
# File 'app/models/feed_aggregated_component.rb', line 6

def self.created_today(feed, reference, secondary_reference = nil)
  time_scope('created', Date.today, feed, reference, secondary_reference)
end

.destroyed_today(feed, reference, secondary_reference = nil) ⇒ Object



18
19
20
# File 'app/models/feed_aggregated_component.rb', line 18

def self.destroyed_today(feed, reference, secondary_reference = nil)
  time_scope('destroyed', Date.today, feed, reference, secondary_reference)
end

.time_scope(action, time, feed, reference, secondary_reference) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'app/models/feed_aggregated_component.rb', line 22

def self.time_scope(action, time, feed, reference, secondary_reference)
  scope = where(:action => action, :feed_id => feed.id, :reference_type => reference.class.to_s, :reference_id => reference.id)
  scope = scope.where("created_at > ?", time)
  
  if secondary_reference.present?
    scope = scope.where(:secondary_reference_type => secondary_reference.class.to_s, :secondary_reference_id => secondary_reference.id)
  end
  
  return scope.first
end

.updated_today(feed, reference, secondary_reference = nil) ⇒ Object



14
15
16
# File 'app/models/feed_aggregated_component.rb', line 14

def self.updated_today(feed, reference, secondary_reference = nil)
  time_scope('updated', Date.today, feed, reference, secondary_reference)
end