Sha256: 34e3551a2d6abda6b225c14a106f5736965fc4c75528ea649910faac7acb993e
Contents?: true
Size: 1.05 KB
Versions: 2
Compression:
Stored size: 1.05 KB
Contents
# frozen_string_literal: true require 'weakref' module BulkLoader module DSL module ClassMethods # 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. def bulk_loader(*args, &block) @bulk_loader ||= BulkLoader::ClassAttribute.new return @bulk_loader if args.empty? name, mapping, options = *args options ||= {} does_export = options.delete(:export) @bulk_loader.define_loader(name, BulkLoader::Loader.new(mapping, options, &block)) return if does_export == false define_method name do bulk_loader.public_send(name) end end end def self.included(mod) mod.extend(ClassMethods) end def bulk_loader return @bulk_loader if @bulk_loader class_attribute = self.class.bulk_loader @bulk_loader = BulkLoader::Attribute.new(class_attribute, WeakRef.new(self)) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
bulk_loader-0.2.0 | lib/bulk_loader/dsl.rb |
bulk_loader-0.1.0 | lib/bulk_loader/dsl.rb |