Class: Serega::SeregaPlugins::Batch::BatchConfig
- Inherits:
-
Object
- Object
- Serega::SeregaPlugins::Batch::BatchConfig
- Defined in:
- lib/serega/plugins/batch/lib/batch_config.rb
Overview
Batch plugin config
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#auto_hide ⇒ Boolean?
Shows option to auto hide attributes with :batch specified.
-
#auto_hide=(value) ⇒ Boolean
New option value.
-
#define(loader_name, callable = nil, &block) ⇒ void
Defines batch loader.
-
#id_method ⇒ Symbol, ...
Shows method name or callable object needed to get object identifier for batch load.
-
#id_method=(value) ⇒ Boolean
Sets new identifier method name or callable value needed for batch loading.
-
#initialize(opts) ⇒ BatchConfig
constructor
A new instance of BatchConfig.
-
#loaders ⇒ Hash
Shows defined loaders.
Constructor Details
#initialize(opts) ⇒ BatchConfig
Returns a new instance of BatchConfig.
12 13 14 |
# File 'lib/serega/plugins/batch/lib/batch_config.rb', line 12 def initialize(opts) @opts = opts end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
10 11 12 |
# File 'lib/serega/plugins/batch/lib/batch_config.rb', line 10 def opts @opts end |
Instance Method Details
#auto_hide ⇒ Boolean?
Shows option to auto hide attributes with :batch specified
49 50 51 |
# File 'lib/serega/plugins/batch/lib/batch_config.rb', line 49 def auto_hide opts[:auto_hide] end |
#auto_hide=(value) ⇒ Boolean
Returns New option value.
55 56 57 58 |
# File 'lib/serega/plugins/batch/lib/batch_config.rb', line 55 def auto_hide=(value) raise SeregaError, "Must have boolean value, #{value.inspect} provided" if (value != true) && (value != false) opts[:auto_hide] = value end |
#define(loader_name, callable = nil, &block) ⇒ void
This method returns an undefined value.
Defines batch loader
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/serega/plugins/batch/lib/batch_config.rb', line 25 def define(loader_name, callable = nil, &block) if (!callable && !block) || (callable && block) raise SeregaError, "Batch loader can be specified with one of arguments - callable value or &block" end callable ||= block SeregaValidations::Utils::CheckExtraKeywordArg.call(callable, "batch loader `#{loader_name}`") params_count = SeregaUtils::ParamsCount.call(callable, max_count: 3) if params_count > 3 raise SeregaError, "Batch loader can have maximum 3 parameters (ids, context, plan)" end loaders[loader_name] = callable end |
#id_method ⇒ Symbol, ...
Shows method name or callable object needed to get object identifier for batch load
62 63 64 |
# File 'lib/serega/plugins/batch/lib/batch_config.rb', line 62 def id_method opts[:id_method] end |
#id_method=(value) ⇒ Boolean
Sets new identifier method name or callable value needed for batch loading
70 71 72 73 |
# File 'lib/serega/plugins/batch/lib/batch_config.rb', line 70 def id_method=(value) CheckBatchOptIdMethod.call(value) opts[:id_method] = value end |
#loaders ⇒ Hash
Shows defined loaders
43 44 45 |
# File 'lib/serega/plugins/batch/lib/batch_config.rb', line 43 def loaders opts[:loaders] end |