Method: MasterLoader#initialize

Defined in:
lib/master_loader.rb

#initialize(**options, &block) ⇒ MasterLoader

Returns a new instance of MasterLoader.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/master_loader.rb', line 115

def initialize(**options, &block)
  unless block_given?
    raise TypeError, "Dataloader must be constructed with a block which accepts " \
      "Array and returns either Array or Hash of the same size (or Promise)"
  end

  @name = options.delete(:name)
  @cache = if options.has_key?(:cache)
             options.delete(:cache) || NoCache.new
           else
             Cache.new
           end
  @max_batch_size = options.fetch(:max_batch_size, Float::INFINITY)

  @interceptor = options.delete(:interceptor) || lambda { |n|
    lambda { |ids|
      n.call(ids)
    }
  }

  @loader_block = @interceptor.call(block)
end