Method: Hackeroo::Cursor#initialize

Defined in:
lib/hackeroo/cursor.rb

#initialize(attrs, collection_name, klass, client, method_name, method_options) ⇒ Hackeroo::Cursor

Initializes a new Cursor

Parameters:

  • attrs (Hash)
  • collection_name (String, Symbol)

    The name of the method to return the collection

  • klass (Class)

    The class to instantiate object in the collection

  • client (Hackeroo::Client)
  • method_name (String, Symbol)
  • method_options (Hash)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/hackeroo/cursor.rb', line 31

def initialize(attrs, collection_name, klass, client, method_name, method_options)
  @attrs = attrs
  @client = client
  @method_name = method_name
  @method_options = method_options
  @collection = Array(attrs[collection_name.to_sym]).map do |item|
    if klass
      klass.fetch_or_new(item)
    else
      item
    end
  end
  singleton_class.class_eval do
    alias_method(collection_name.to_sym, :collection)
  end
end