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(**, &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 = .delete(:name) @cache = if .has_key?(:cache) .delete(:cache) || NoCache.new else Cache.new end @max_batch_size = .fetch(:max_batch_size, Float::INFINITY) @interceptor = .delete(:interceptor) || lambda { |n| lambda { |ids| n.call(ids) } } @loader_block = @interceptor.call(block) end |