Class: Serega::SeregaPlugins::Batch::BatchModel
- Inherits:
-
Object
- Object
- Serega::SeregaPlugins::Batch::BatchModel
- Defined in:
- lib/serega/plugins/batch/batch.rb
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
-
#initialize(opts, loaders, many) ⇒ BatchModel
constructor
A new instance of BatchModel.
- #key ⇒ Object
- #loader ⇒ Object
Constructor Details
#initialize(opts, loaders, many) ⇒ BatchModel
Returns a new instance of BatchModel.
78 79 80 81 82 |
# File 'lib/serega/plugins/batch/batch.rb', line 78 def initialize(opts, loaders, many) @opts = opts @loaders = loaders @many = many end |
Instance Attribute Details
#loaders ⇒ Object (readonly)
Returns the value of attribute loaders.
76 77 78 |
# File 'lib/serega/plugins/batch/batch.rb', line 76 def loaders @loaders end |
#many ⇒ Object (readonly)
Returns the value of attribute many.
76 77 78 |
# File 'lib/serega/plugins/batch/batch.rb', line 76 def many @many end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
76 77 78 |
# File 'lib/serega/plugins/batch/batch.rb', line 76 def opts @opts end |
Instance Method Details
#default_value ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/serega/plugins/batch/batch.rb', line 99 def default_value if opts.key?(:default) opts[:default] elsif many FROZEN_EMPTY_ARRAY end end |
#key ⇒ Object
92 93 94 95 96 97 |
# File 'lib/serega/plugins/batch/batch.rb', line 92 def key @batch_key ||= begin key = opts[:key] key.is_a?(Symbol) ? proc { |object| object.public_send(key) } : key end end |
#loader ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/serega/plugins/batch/batch.rb', line 84 def loader @batch_loader ||= begin loader = opts[:loader] loader = loaders.fetch(loader) if loader.is_a?(Symbol) loader end end |