Sha256: af6e9a885b9df938705ff2229378afe35bd7d7c533bae424fb25dfb5e56d94b8

Contents?: true

Size: 1.24 KB

Versions: 17

Compression:

Stored size: 1.24 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(
            self.collection.next.merge(
              _options_
            )
          )
        )
      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

17 entries across 17 versions & 1 rubygems

Version Path
fb_graph-2.7.17 lib/fb_graph/connection.rb
fb_graph-2.7.16 lib/fb_graph/connection.rb
fb_graph-2.7.15 lib/fb_graph/connection.rb
fb_graph-2.7.14 lib/fb_graph/connection.rb
fb_graph-2.7.13 lib/fb_graph/connection.rb
fb_graph-2.7.12 lib/fb_graph/connection.rb
fb_graph-2.7.11 lib/fb_graph/connection.rb
fb_graph-2.7.10 lib/fb_graph/connection.rb
fb_graph-2.7.9 lib/fb_graph/connection.rb
fb_graph-2.7.8 lib/fb_graph/connection.rb
fb_graph-2.7.7 lib/fb_graph/connection.rb
fb_graph-2.7.6 lib/fb_graph/connection.rb
fb_graph-2.7.5 lib/fb_graph/connection.rb
fb_graph-2.7.4 lib/fb_graph/connection.rb
fb_graph-2.7.3 lib/fb_graph/connection.rb
fb_graph-2.7.2 lib/fb_graph/connection.rb
fb_graph-2.7.1 lib/fb_graph/connection.rb