Module: IOPromise::DataLoader::ClassMethods
- Defined in:
- lib/iopromise/data_loader.rb
Instance Method Summary collapse
Instance Method Details
#attr_async(attr_name, build_func = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/iopromise/data_loader.rb', line 6 def attr_async(attr_name, build_func = nil) self.attr_async_names << attr_name if build_func.nil? self.class_eval("def async_#{attr_name};@#{attr_name};end") else self.define_method("async_#{attr_name}") do @attr_async_memo ||= {} @attr_async_memo[attr_name] ||= self.instance_exec(&build_func) end end self.class_eval("def #{attr_name};async_#{attr_name}.sync;end") end |
#attr_async_names ⇒ Object
21 22 23 |
# File 'lib/iopromise/data_loader.rb', line 21 def attr_async_names @attr_async_names ||= [] end |