Ruby on rails 设计-如何利用Rails API应用程序中的OOP构建过滤器

Ruby on rails 设计-如何利用Rails API应用程序中的OOP构建过滤器,ruby-on-rails,ruby,oop,Ruby On Rails,Ruby,Oop,我的应用程序在提要中显示项目。这些项目是由不同的用户进行的评级。评级可以有一个值、一个评价等。 通常情况下,登录用户请求feed/users/feed。控制器执行以下操作: def feed if authenticate_with_token imos_and_cursor = Feed.new(RandomItemFeeder.new(params[:cursor], @current_user)).feed render json: {cursor: imo

我的应用程序在提要中显示项目。这些项目是由不同的用户进行的评级。评级可以有一个值、一个评价等。 通常情况下,登录用户请求feed/users/feed。控制器执行以下操作:

def feed
    if authenticate_with_token
      imos_and_cursor = Feed.new(RandomItemFeeder.new(params[:cursor], @current_user)).feed
      render json: {cursor: imos_and_cursor[imos_and_cursor.length-1], imos: imos_and_cursor[0..imos_and_cursor.length-2]} 
    end
  end
Feed是这里的老板。它控制所提供的服务,它使用项目进行响应,但它也知道如何响应,以便基本上满足用户的人员呼叫索引。 以下是我的一些馈线: 朋友进料器 随机项进料器 MOST百分位进料器

以下是RandomItemFeeder,负责随机项目的馈送:

class RandomItemFeeder < Feeder

    def feed

        influencers_ids = User.influencers.distinct(:id)
        friends = User.friends(@watching_user).distinct(:id) if @watching_user
        source_users = influencers_ids.concat(friends)

        Rating.random_from_influencers(@watching_user, source_users).scroll(@current_cursor) do |rating, cursor|
            @next_cursor = cursor
            @feed << ImoPresenter.new(Imo.new(rating), @watching_user)
        end

        @feed << @next_cursor.to_s

    end

end
演讲者

我已经用演示者构建了JSON的呈现,因此对于不同的案例提要、用户配置文件等,我有不同的演示者

现在,我想合并过滤器。例如,我希望RandomItemFeeder只提供过去5年的项目。显然,项目模型有相应的字段

问题是我如何利用最佳OOP实践来整合这种过滤。最后,它只是一个范围,我可以用不同的方式实现它,但我只想现在就做,这样我就不必回来重构所有东西

提前谢谢