Note there is some funkiness going on with class loadings
Had to create a `feed` and `widget_feed` table even though in this
first version the Widget::Feed includes only uses ActiveModel instead
of ActiveRecord, otherwise some specs failed
We’ll figure it out and clean up 😌
46 lines
748 B
Ruby
46 lines
748 B
Ruby
class Widget
|
|
class Feed
|
|
include ActiveModel::Model
|
|
|
|
KINDS = %w(proposals debates processes)
|
|
|
|
attr_accessor :kind
|
|
|
|
def initialize(attributes={})
|
|
super
|
|
@kind = attributes[:kind]
|
|
end
|
|
|
|
def active?(kind)
|
|
Setting["feature.homepage.widgets.feeds.#{kind}"].present?
|
|
end
|
|
|
|
def self.active
|
|
KINDS.collect do |kind|
|
|
feed = new(kind: kind)
|
|
feed if feed.active?(kind)
|
|
end.compact
|
|
end
|
|
|
|
def items
|
|
send(kind)
|
|
end
|
|
|
|
def proposals
|
|
Proposal.sort_by_hot_score.limit(limit)
|
|
end
|
|
|
|
def debates
|
|
Debate.sort_by_hot_score.limit(limit)
|
|
end
|
|
|
|
def processes
|
|
Legislation::Process.open.limit(limit)
|
|
end
|
|
|
|
def limit
|
|
3
|
|
end
|
|
|
|
end
|
|
end |