Class: BatchLoader
- Inherits:
-
Object
show all
- Defined in:
- lib/batch_loader.rb,
lib/batch_loader/graphql.rb,
lib/batch_loader/version.rb,
lib/batch_loader/executor.rb,
lib/batch_loader/middleware.rb,
lib/batch_loader/executor_proxy.rb
Defined Under Namespace
Classes: Executor, ExecutorProxy, GraphQL, Middleware
Constant Summary
collapse
- NoBatchError =
Class.new(StandardError)
- VERSION =
"1.0.0"
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of BatchLoader.
15
16
17
|
# File 'lib/batch_loader.rb', line 15
def initialize(item:)
@item = item
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
39
40
41
|
# File 'lib/batch_loader.rb', line 39
def method_missing(method_name, *args, &block)
sync!.public_send(method_name, *args, &block)
end
|
Class Method Details
.for(item) ⇒ Object
11
12
13
|
# File 'lib/batch_loader.rb', line 11
def self.for(item)
new(item: item)
end
|
Instance Method Details
#batch(cache: true, &batch_block) ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/batch_loader.rb', line 19
def batch(cache: true, &batch_block)
@cache = cache
@batch_block = batch_block
executor_proxy.add(item: @item)
singleton_class.class_eval { undef_method(:batch) }
self
end
|
#batch_loader? ⇒ Boolean
29
30
31
|
# File 'lib/batch_loader.rb', line 29
def batch_loader?
true
end
|
#respond_to?(method_name) ⇒ Boolean
33
34
35
|
# File 'lib/batch_loader.rb', line 33
def respond_to?(method_name)
method_name == :batch_loader? || method_missing(:respond_to?, method_name)
end
|