Module: BulkLoader::DSL::ClassMethods

Defined in:
lib/bulk_loader/dsl.rb

Instance Method Summary collapse

Instance Method Details

#bulk_loader(*args, export: nil, autoload: true, default: nil, &block) ⇒ Object

getter for BulkLoader::ClassAttribute If you pass name, mapping, options argument, you can define loader if you does not want to export name to object, pass export: false to options. if you would like to raise error when implicitly calling loader, pass autoload: false to options.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bulk_loader/dsl.rb', line 11

def bulk_loader(*args, export: nil, autoload: true, default: nil, &block)
  @bulk_loader ||= if superclass.respond_to?(:bulk_loader)
                     superclass.bulk_loader.dup
                   else
                     BulkLoader::ClassAttribute.new
                   end

  return @bulk_loader if args.empty?

  name, mapping = *args

  loader = BulkLoader::Loader.new(mapping, default: default, &block)
  @bulk_loader.define_loader(name, loader, autoload: autoload)

  return if export == false

  define_method name do
    bulk_loader.public_send(name)
  end
end