lib/tap/support/executable.rb in bahuvrihi-tap-0.11.2 vs lib/tap/support/executable.rb in bahuvrihi-tap-0.12.0
- old
+ new
@@ -8,11 +8,11 @@
# The App receiving self during enq
attr_reader :app
# The method called during _execute
- attr_reader :_method_name
+ attr_reader :method_name
# The block called when _execute completes
attr_reader :on_complete_block
# An array of dependency indicies that will be resolved on _execute
@@ -26,31 +26,32 @@
# Extends obj with Executable and sets up all required variables. The
# specified method will be called on _execute.
def self.initialize(obj, method_name, app=App.instance, batch=[], dependencies=[], &on_complete_block)
obj.extend Executable
obj.instance_variable_set(:@app, app)
- obj.instance_variable_set(:@_method_name, method_name)
+ obj.instance_variable_set(:@method_name, method_name)
obj.instance_variable_set(:@on_complete_block, on_complete_block)
obj.instance_variable_set(:@dependencies, dependencies)
obj.instance_variable_set(:@batch, batch)
batch << obj
obj
end
- # Initializes a new batch object and adds the object to batch.
- # The object will be a duplicate of self. (Note this method
- # can raise an error for objects that don't support dup,
- # notably Method objects generated by Object#_method).
+ # Initializes a new batch object and adds the object to batch. The object
+ # will be a duplicate of self.
+ #
+ # Note this method can raise an error for objects that don't support dup,
+ # notably Method objects generated by Object#_method.
def initialize_batch_obj
obj = self.dup
if obj.kind_of?(Executable)
batch << obj
obj
else
- Executable.initialize(obj, _method_name, app, batch, dependencies, &on_complete_block)
+ Executable.initialize(obj, method_name, app, batch, dependencies, &on_complete_block)
end
end
# Returns true if the batch size is greater than one
# (the one is assumed to be self).
@@ -123,11 +124,11 @@
self
end
# Enqueues each member of batch (and implicitly self) to app with the
# inputs. The number of inputs provided should match the number of
- # inputs for the _method_name method.
+ # inputs for the method_name method.
def enq(*inputs)
batch.each do |executable|
executable.unbatched_enq(*inputs)
end
self
@@ -191,14 +192,14 @@
def sync_merge(*sources, &block) # :yields: _result
Joins::SyncMerge.join(self, sources, &block)
end
# Sets a switch workflow pattern for self. When _execute completes,
- # switch yields the audited result to the block which should return
- # the index of the target to enque with the results. No target will
- # be enqued if the index is false or nil; an error is raised if no
- # target can be found for the specified index. See Joins::Switch.
+ # switch yields the audited result to the block and the block should
+ # return the index of the target to enque with the results. No target
+ # will be enqued if the index is false or nil. An error is raised if
+ # no target can be found for the specified index. See Joins::Switch.
def switch(*targets, &block) # :yields: _result
Joins::Switch.join(self, targets, &block)
end
# Adds the dependency to each member in batch (and implicitly self).
@@ -234,69 +235,46 @@
def reset_dependencies
dependencies.each {|dependency| dependency.reset }
self
end
- # Auditing method call. Resolves dependencies, executes _method_name,
+ # Auditing method call. Resolves dependencies, executes method_name,
# and sends the audited result to the on_complete_block (if set).
#
- # Audits are initialized in the follwing manner:
- # no inputs:: Creates a new, empty Audit. The first value of the audit
- # will be the result of call.
- # one input:: Forks the input if it is an audit, otherwise initializes
- # a new audit using the input.
- # multiple inputs:: Merges the inputs into a new Audit.
- #
+ # Returns the audited result.
def _execute(*inputs)
resolve_dependencies
- audit = case inputs.length
- when 0 then Audit.new
- when 1
- audit = inputs.first
- if audit.kind_of?(Audit)
- inputs = [audit._current]
- audit._fork
+ previous = []
+ inputs.collect! do |input|
+ if input.kind_of?(Audit)
+ previous << input
+ input.value
else
- Audit.new(audit)
- end
- else
- sources = []
- inputs.collect! do |input|
- if input.kind_of?(Audit)
- sources << input._fork
- input._current
- else
- sources << nil
- input
- end
+ previous << Audit.new(nil, input)
+ input
end
- Audit.new(inputs, sources)
end
-
- audit._record(self, send(_method_name, *inputs))
+
+ audit = Audit.new(self, send(method_name, *inputs), previous)
on_complete_block ? on_complete_block.call(audit) : app.aggregator.store(audit)
audit
end
- # Calls _execute with the inputs and returns the un-audited result.
+ # Calls _execute with the inputs and returns the non-audited result.
# Execute is not a batched method.
def execute(*inputs)
- _execute(*inputs)._current
+ _execute(*inputs).value
end
# Raises a TerminateError if app.state == State::TERMINATE.
# check_terminate may be called at any time to provide a
# breakpoint in long-running processes.
def check_terminate
if app.state == App::State::TERMINATE
raise App::TerminateError.new
end
- end
-
- def inspect
- "#<#{self.class.to_s}:#{object_id} _method: #{_method_name} batch_length: #{batch.length} app: #{app}>"
end
end
end
end
\ No newline at end of file