Class: Feed

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveModel::ForbiddenAttributesProtection, PublicActivity::Common
Defined in:
app/models/feed.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) subscribable(screen, field)

The set of feeds available to be subscribed to a (screen, field) pair.

All accessible feeds - currently subscribed


82
83
84
85
86
87
88
# File 'app/models/feed.rb', line 82

def self.subscribable(screen, field)
  subscriptions = Subscription.where(:screen_id => screen, :field_id => field)
  current_feeds = subscriptions.collect{ |s| s.feed }

  accessible_feeds = Feed.accessible_by(Ability.new(screen), :read)
  accessible_feeds - current_feeds
end

Instance Method Details

- (Object) ancestors

Collect a list of parent feeds. Each feed the monkey stops as he climbs up the tree. Compliments of DHH github.com/rails/acts_as_tree



48
49
50
51
52
# File 'app/models/feed.rb', line 48

def ancestors
  node, nodes = self, []
  nodes << node = node.parent while node.parent
  nodes
end

- (Object) depth

Figure out how deep in the tree the current feed is. 0 = root



71
72
73
# File 'app/models/feed.rb', line 71

def depth
  ancestors.count
end

- (Object) descendants

Collect recursive list of child feeds. Every feed the monkey could stop by as he climbs down a tree. Compliments of github.com/funkensturm/acts_as_category



58
59
60
61
62
63
64
65
66
67
# File 'app/models/feed.rb', line 58

def descendants
  node, nodes = self, []
  node.children.each { |child|
    if !nodes.include?(child) #Try and stop any circular dependencies
      nodes += [child]
      nodes += child.descendants
    end
  } unless node.children.empty?
  nodes
end

- (Boolean) is_root?

Test if this feed is a root feed or not



40
41
42
# File 'app/models/feed.rb', line 40

def is_root?
  parent_id.nil?
end

- (Object) parent_id_cannot_be_this_feed



28
29
30
31
32
# File 'app/models/feed.rb', line 28

def parent_id_cannot_be_this_feed
  if !parent_id.blank? and parent_id == id
    errors.add(:parent_id, I18n.t(:cant_be_this_feed))
  end
end

- (Object) self_and_siblings

The group of feeds who share a common parent.



76
77
78
# File 'app/models/feed.rb', line 76

def self_and_siblings
  parent ? parent.children : Feed.roots
end

- (Object) shown_on_screens

Generate a unique list of screens on which this feed appears



24
25
26
# File 'app/models/feed.rb', line 24

def shown_on_screens
  return subscriptions.collect{|s| s.screen }.uniq
end

- (Object) submissions_to_moderate

Figure out which submissions need to be moderated. This is a list of all the pending submissions minus dynamic content who have a parent pending moderation (since that moderation will propogate automatically).



93
94
95
96
97
98
99
100
# File 'app/models/feed.rb', line 93

def submissions_to_moderate
  moderate = self.submissions.pending.all
  moderate_content = moderate.collect{|s| s.content}
  moderate.reject! do |s|
    !s.content.parent.nil? && moderate_content.include?(s.content.parent)
  end
  return moderate
end