class Strategize::OperationGroup
Attributes
operations[R]
@attr_reader operations [Array<Operation>]
Public Class Methods
new(operations=[])
click to toggle source
Create a new instance of OperationGroup
@param operations [Array<Operation>] the operations to be executed
# File lib/strategize/operations/operation_group.rb, line 9 def initialize(operations=[]) @operations = operations end
Public Instance Methods
add(name, function)
click to toggle source
Add Operation
to group
@param name [Symbol] a descriptive name for the operation @param operation [Proc] a proc or lambda describing the code to be executed
# File lib/strategize/operations/operation_group.rb, line 17 def add(name, function) operation = Operation.new(name, function) @operations.push(operation) end
run(subjects)
click to toggle source
Execute the code definined in each operation against a subject.
@param subject [Object] a single object which acts as the subject for each operation @param subject [Hash] a hash of operation names and subjects
# File lib/strategize/operations/operation_group.rb, line 26 def run(subjects) the_subjects = subjects the_subjects = build_subjects_hash(subjects) unless subjects.is_a?(Hash) @operations.each do |operation| subject = the_subjects[operation.name] operation.process(subject) unless subject.nil? end end
Private Instance Methods
build_subjects_hash(subjects)
click to toggle source
# File lib/strategize/operations/operation_group.rb, line 39 def build_subjects_hash(subjects) { default: subjects } end