Class: Serega::SeregaPlugins::Batch::BatchLoadersConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/serega/plugins/batch/batch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ BatchLoadersConfig

Returns a new instance of BatchLoadersConfig.



53
54
55
# File 'lib/serega/plugins/batch/batch.rb', line 53

def initialize(opts)
  @opts = opts
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



51
52
53
# File 'lib/serega/plugins/batch/batch.rb', line 51

def opts
  @opts
end

Instance Method Details

#define(loader_name, &block) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/serega/plugins/batch/batch.rb', line 57

def define(loader_name, &block)
  unless block
    raise SeregaError, "Block must be given to batch_loaders.define method"
  end

  params = block.parameters
  if params.count > 3 || !params.map!(&:first).all? { |type| (type == :req) || (type == :opt) }
    raise SeregaError, "Block can have maximum 3 regular parameters"
  end

  opts[loader_name] = block
end

#fetch(loader_name) ⇒ Object



70
71
72
# File 'lib/serega/plugins/batch/batch.rb', line 70

def fetch(loader_name)
  opts[loader_name] || (raise SeregaError, "Batch loader with name `#{loader_name.inspect}` was not defined. Define example: config.batch_loaders.define(:#{loader_name}) { |keys, ctx, points| ... }")
end