Class: FbGraph::Connection

Inherits:
Collection show all
Defined in:
lib/fb_graph/connection.rb

Instance Attribute Summary (collapse)

Attributes inherited from Collection

#cursors, #total_count, #unread_count, #updated_time

Instance Method Summary (collapse)

Constructor Details

- (Connection) initialize(owner, connection, options = {})



6
7
8
9
10
11
12
# File 'lib/fb_graph/connection.rb', line 6

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

Instance Attribute Details

- (Object) collection

Returns the value of attribute collection



3
4
5
# File 'lib/fb_graph/connection.rb', line 3

def collection
  @collection
end

- (Object) connection

Returns the value of attribute connection



3
4
5
# File 'lib/fb_graph/connection.rb', line 3

def connection
  @connection
end

- (Object) options

Returns the value of attribute options



3
4
5
# File 'lib/fb_graph/connection.rb', line 3

def options
  @options
end

- (Object) owner

Returns the value of attribute owner



3
4
5
# File 'lib/fb_graph/connection.rb', line 3

def owner
  @owner
end

Instance Method Details

- (Object) next(_options_ = {})



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fb_graph/connection.rb', line 14

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

- (Object) previous(_options_ = {})



36
37
38
39
40
41
42
# File 'lib/fb_graph/connection.rb', line 36

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