module ObjectPatch::OperationFactory
A factory module used to build the appropriate operation objects.
Public Class Methods
build(patch)
click to toggle source
Build an operation object that matches the operation type and makes the appropriate information available to them.
@param [Hash] patch @return [Object] One of the operations classes.
# File lib/object_patch/operation_factory.rb, line 12 def build(patch) operations = ObjectPatch::Operations.constants.map { |c| c.to_s.downcase } unless operations.include?(patch['op']) raise InvalidOperation, "Invalid operation: `#{patch['op']}`" end Operations.const_get(patch['op'].capitalize.to_sym).new(patch) end
Private Instance Methods
build(patch)
click to toggle source
Build an operation object that matches the operation type and makes the appropriate information available to them.
@param [Hash] patch @return [Object] One of the operations classes.
# File lib/object_patch/operation_factory.rb, line 12 def build(patch) operations = ObjectPatch::Operations.constants.map { |c| c.to_s.downcase } unless operations.include?(patch['op']) raise InvalidOperation, "Invalid operation: `#{patch['op']}`" end Operations.const_get(patch['op'].capitalize.to_sym).new(patch) end