Class: Serega::SeregaPlugins::Batch::BatchLoadersConfig
- Inherits:
-
Object
- Object
- Serega::SeregaPlugins::Batch::BatchLoadersConfig
- Defined in:
- lib/serega/plugins/batch/batch.rb
Overview
Batch loader config
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#define(loader_name, &block) ⇒ void
Defines batch loader.
-
#fetch(loader_name) ⇒ Proc
Finds previously defined batch loader by name.
-
#initialize(opts) ⇒ BatchLoadersConfig
constructor
A new instance of BatchLoadersConfig.
Constructor Details
#initialize(opts) ⇒ BatchLoadersConfig
Returns a new instance of BatchLoadersConfig.
106 107 108 |
# File 'lib/serega/plugins/batch/batch.rb', line 106 def initialize(opts) @opts = opts end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
104 105 106 |
# File 'lib/serega/plugins/batch/batch.rb', line 104 def opts @opts end |
Instance Method Details
#define(loader_name, &block) ⇒ void
This method returns an undefined value.
Defines batch loader
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/serega/plugins/batch/batch.rb', line 119 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) ⇒ Proc
Finds previously defined batch loader by name
138 139 140 |
# File 'lib/serega/plugins/batch/batch.rb', line 138 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 |