Class: Serega::SeregaPlugins::Batch::BatchModel
- Inherits:
-
Object
- Object
- Serega::SeregaPlugins::Batch::BatchModel
- Defined in:
- lib/serega/plugins/batch/batch.rb
Overview
Stores batch config for specific attribute
Instance Attribute Summary collapse
-
#loaders ⇒ Object
readonly
Returns the value of attribute loaders.
-
#many ⇒ Object
readonly
Returns the value of attribute many.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#default_value ⇒ Object
Default value for missing key.
-
#initialize(opts, loaders, many) ⇒ void
constructor
Initializes batch model.
-
#key ⇒ Object
Key (uid) of batch loaded object.
-
#loader ⇒ #call
Batch loader.
Constructor Details
#initialize(opts, loaders, many) ⇒ void
Initializes batch model
156 157 158 159 160 |
# File 'lib/serega/plugins/batch/batch.rb', line 156 def initialize(opts, loaders, many) @opts = opts @loaders = loaders @many = many end |
Instance Attribute Details
#loaders ⇒ Object (readonly)
Returns the value of attribute loaders.
146 147 148 |
# File 'lib/serega/plugins/batch/batch.rb', line 146 def loaders @loaders end |
#many ⇒ Object (readonly)
Returns the value of attribute many.
146 147 148 |
# File 'lib/serega/plugins/batch/batch.rb', line 146 def many @many end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
146 147 148 |
# File 'lib/serega/plugins/batch/batch.rb', line 146 def opts @opts end |
Instance Method Details
#default_value ⇒ Object
Returns default value for missing key.
180 181 182 183 184 185 186 |
# File 'lib/serega/plugins/batch/batch.rb', line 180 def default_value if opts.key?(:default) opts[:default] elsif many FROZEN_EMPTY_ARRAY end end |
#key ⇒ Object
Returns key (uid) of batch loaded object.
172 173 174 175 176 177 |
# File 'lib/serega/plugins/batch/batch.rb', line 172 def key @batch_key ||= begin key = opts[:key] key.is_a?(Symbol) ? proc { |object| object.public_send(key) } : key end end |
#loader ⇒ #call
Returns batch loader.
163 164 165 166 167 168 169 |
# File 'lib/serega/plugins/batch/batch.rb', line 163 def loader @batch_loader ||= begin loader = opts[:loader] loader = loaders.fetch(loader) if loader.is_a?(Symbol) loader end end |