Class: Serega::SeregaPlugins::Batch::BatchModel

Inherits:
Object
  • Object
show all
Defined in:
lib/serega/plugins/batch/batch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#loadersObject (readonly)

Returns the value of attribute loaders.



76
77
78
# File 'lib/serega/plugins/batch/batch.rb', line 76

def loaders
  @loaders
end

#manyObject (readonly)

Returns the value of attribute many.



76
77
78
# File 'lib/serega/plugins/batch/batch.rb', line 76

def many
  @many
end

#optsObject (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_valueObject



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

#keyObject



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

#loaderObject



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