Sha256: d52c99d1cd1d7697882fe780ae7e8f471f7a1234d262708ec97dfe1adb0612bd

Contents?: true

Size: 1.16 KB

Versions: 52

Compression:

Stored size: 1.16 KB

Contents

module FbGraph
  class Connection < Collection
    attr_accessor :collection, :connection, :owner, :options
    delegate :total_count, :unread_count, :updated_time, :to => :collection

    def initialize(owner, connection, options = {})
      @owner = owner
      @options = options
      @connection = connection
      @collection = options.delete(:collection) || Collection.new
      replace collection
    end

    def next(_options_ = {})
      if self.collection.next.present?
        connection_method = if self.owner.respond_to?(self.connection)
          self.connection
        else
          self.owner.public_methods.detect do |method|
            method.to_s.gsub('_', '') == self.connection.to_s
          end
        end
        self.owner.send(connection_method, self.options.merge(_options_).merge(self.collection.next))
      else
        self.class.new(self.owner, self.connection)
      end
    end

    def previous(_options_ = {})
      if self.collection.previous.present?
        self.owner.send(self.connection, self.options.merge(_options_).merge(self.collection.previous))
      else
        self.class.new(self.owner, self.connection)
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
fb_graph-2.7.0 lib/fb_graph/connection.rb
fb_graph-2.6.7 lib/fb_graph/connection.rb
fb_graph-2.6.6 lib/fb_graph/connection.rb
fb_graph-2.6.5 lib/fb_graph/connection.rb
fb_graph-2.6.4 lib/fb_graph/connection.rb
fb_graph-2.6.3 lib/fb_graph/connection.rb
fb_graph-2.6.2 lib/fb_graph/connection.rb
fb_graph-2.6.1 lib/fb_graph/connection.rb
fb_graph-2.6.0 lib/fb_graph/connection.rb
fb_graph-2.5.9 lib/fb_graph/connection.rb
fb_graph-2.5.8 lib/fb_graph/connection.rb
fb_graph-2.5.7 lib/fb_graph/connection.rb
fb_graph-2.5.6 lib/fb_graph/connection.rb
fb_graph-2.5.5 lib/fb_graph/connection.rb
fb_graph-2.5.4 lib/fb_graph/connection.rb
fb_graph-2.5.3 lib/fb_graph/connection.rb
fb_graph-2.5.2 lib/fb_graph/connection.rb
fb_graph-2.5.1 lib/fb_graph/connection.rb
fb_graph-2.5.0 lib/fb_graph/connection.rb
fb_graph-2.4.20 lib/fb_graph/connection.rb