Class: Serega::SeregaPlugins::Batch::BatchConfig
- Inherits:
-
Object
- Object
- Serega::SeregaPlugins::Batch::BatchConfig
- 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
-
#auto_hide ⇒ Boolean?
Shows option to auto hide attributes with :batch specified.
-
#auto_hide=(value) ⇒ Boolean
New option value.
-
#default_key ⇒ Symbol?
Shows default key for :batch option.
-
#default_key=(value) ⇒ Boolean
New option value.
-
#define(loader_name, &block) ⇒ void
Defines batch loader.
-
#fetch_loader(loader_name) ⇒ Proc
Finds previously defined batch loader by name.
-
#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.
144 145 146 |
# File 'lib/serega/plugins/batch/batch.rb', line 144 def initialize(opts) @opts = opts end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
142 143 144 |
# File 'lib/serega/plugins/batch/batch.rb', line 142 def opts @opts end |
Instance Method Details
#auto_hide ⇒ Boolean?
Shows option to auto hide attributes with :batch specified
188 189 190 |
# File 'lib/serega/plugins/batch/batch.rb', line 188 def auto_hide opts[:auto_hide] end |
#auto_hide=(value) ⇒ Boolean
Returns New option value.
194 195 196 197 |
# File 'lib/serega/plugins/batch/batch.rb', line 194 def auto_hide=(value) raise SeregaError, "Must have boolean value, #{value.inspect} provided" if (value != true) && (value != false) opts[:auto_hide] = value end |
#default_key ⇒ Symbol?
Shows default key for :batch option
201 202 203 |
# File 'lib/serega/plugins/batch/batch.rb', line 201 def default_key opts[:default_key] end |
#default_key=(value) ⇒ Boolean
Returns New option value.
207 208 209 210 |
# File 'lib/serega/plugins/batch/batch.rb', line 207 def default_key=(value) raise SeregaError, "Must be a Symbol, #{value.inspect} provided" unless value.is_a?(Symbol) opts[:default_key] = value end |
#define(loader_name, &block) ⇒ void
This method returns an undefined value.
Defines batch loader
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/serega/plugins/batch/batch.rb', line 157 def define(loader_name, &block) unless block raise SeregaError, "Block must be given to #define method" end params = block.parameters if params.count > 3 || !params.all? { |param| (param[0] == :req) || (param[0] == :opt) } raise SeregaError, "Block can have maximum 3 regular parameters" end loaders[loader_name] = block end |
#fetch_loader(loader_name) ⇒ Proc
Finds previously defined batch loader by name
182 183 184 |
# File 'lib/serega/plugins/batch/batch.rb', line 182 def fetch_loader(loader_name) loaders[loader_name] || (raise SeregaError, "Batch loader with name `#{loader_name.inspect}` was not defined. Define example: config.batch.define(:#{loader_name}) { |keys, ctx, points| ... }") end |
#loaders ⇒ Hash
Shows defined loaders
172 173 174 |
# File 'lib/serega/plugins/batch/batch.rb', line 172 def loaders opts[:loaders] end |