Module: ObjectPatch::OperationFactory
- Defined in:
- lib/object_patch/operation_factory.rb
Overview
A factory module used to build the appropriate operation objects.
Class Method Summary collapse
-
.build(patch) ⇒ Object
Build an operation object that matches the operation type and makes the appropriate information available to them.
Instance Method Summary collapse
-
#build(patch) ⇒ Object
private
Build an operation object that matches the operation type and makes the appropriate information available to them.
Class Method Details
.build(patch) ⇒ Object
Build an operation object that matches the operation type and makes the appropriate information available to them.
12 13 14 15 16 17 18 19 20 |
# 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 |
Instance Method Details
#build(patch) ⇒ Object (private)
Build an operation object that matches the operation type and makes the appropriate information available to them.
12 13 14 15 16 17 18 19 20 |
# 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 |