Sha256: 408940eaf5b9cb46c5fe6a843a3806fbfc819926e71fa422274d087731ccc2af

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require 'facemock/fb_graph/application/user'

module Facemock
  module FbGraph
    class Application < ActiveRecord::Base
      class TestUsers < Array
        DEFAULT_LIMIT = 50
        DEFAULT_AFTER = 0

        def initialize(application_id, options={})
          @limit = limit = (options[:limit] && options[:limit] > 0) ? options[:limit] : DEFAULT_LIMIT
          @after = after = (options[:after] && options[:after] > 0) ? options[:after] : DEFAULT_AFTER
          @application_id = application_id
          st = after
          ed = after + limit - 1
          users = User.where(application_id: application_id).sort_by{|u| u.created_at}
          users = users.reverse[st..ed] || []
          super(users)
        end

        def collection
          self
        end
        
        def next
          options = { limit: @limit, after: @after + @limit }
          TestUsers.new(@application_id, options)
        end

        def select
          { limit: DEFAULT_LIMIT, after: DEFAULT_AFTER }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
facemock-0.0.2 lib/facemock/fb_graph/application/test_users.rb