class ROM::Changeset::Pipe

Composable data transformation pipe used by default in changesets

@api private

Public Class Methods

[](name_or_proc) click to toggle source
# File lib/rom/changeset/pipe.rb, line 36
def self.[](name_or_proc)
  container[name_or_proc]
end
initialize(**opts) click to toggle source
# File lib/rom/changeset/pipe.rb, line 30
def self.initialize(**opts)
  transformer = allocate
  transformer.__send__(:initialize, dsl.(transformer), **opts)
  transformer
end
new(*args, **opts) click to toggle source
Calls superclass method
# File lib/rom/changeset/pipe.rb, line 22
def self.new(*args, **opts)
  if args.empty?
    initialize(**opts)
  else
    super
  end
end

Public Instance Methods

>>(other, for_diff: other.is_a?(self.class) ? other.use_for_diff : false)
Alias for: compose
[](*args) click to toggle source
# File lib/rom/changeset/pipe.rb, line 40
def [](*args)
  self.class[*args]
end
bind(context) click to toggle source
# File lib/rom/changeset/pipe.rb, line 44
def bind(context)
  if processor.is_a?(Proc)
    bound_processor = self[-> *args { context.instance_exec(*args, &processor) }]
    bound_diff_processor = self[-> *args { context.instance_exec(*args, &diff_processor) }]

    new(bound_processor, diff_processor: bound_diff_processor)
  else
    self
  end
end
call(data) click to toggle source
# File lib/rom/changeset/pipe.rb, line 70
def call(data)
  processor.call(data)
end
compose(other, for_diff: other.is_a?(self.class) ? other.use_for_diff : false) click to toggle source
# File lib/rom/changeset/pipe.rb, line 55
def compose(other, for_diff: other.is_a?(self.class) ? other.use_for_diff : false)
  new_proc = processor >> other

  if for_diff
    diff_proc = diff_processor >> (
      other.is_a?(self.class) ? other.diff_processor : other
    )

    new(new_proc, use_for_diff: true, diff_processor: diff_proc)
  else
    new(new_proc)
  end
end
Also aliased as: >>
for_diff(data) click to toggle source
# File lib/rom/changeset/pipe.rb, line 74
def for_diff(data)
  use_for_diff ? diff_processor.call(data) : data
end
new(processor, **opts) click to toggle source
# File lib/rom/changeset/pipe.rb, line 78
def new(processor, **opts)
  self.class.new(processor, **options, **opts)
end