Class: ROM::Changeset::Pipe Private

Inherits:
Object
  • Object
show all
Extended by:
Initializer
Defined in:
changeset/lib/rom/changeset/pipe.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Composable data transformation pipe used by default in changesets

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](name_or_proc) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



36
37
38
# File 'changeset/lib/rom/changeset/pipe.rb', line 36

def self.[](name_or_proc)
  container[name_or_proc]
end

.initialize(**opts) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



30
31
32
33
34
# File 'changeset/lib/rom/changeset/pipe.rb', line 30

def self.initialize(**opts)
  transformer = allocate
  transformer.__send__(:initialize, dsl.(transformer), **opts)
  transformer
end

.new(*args, **opts) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
25
26
27
28
# File 'changeset/lib/rom/changeset/pipe.rb', line 22

def self.new(*args, **opts)
  if args.empty?
    initialize(**opts)
  else
    super
  end
end

Instance Method Details

#[](*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
# File 'changeset/lib/rom/changeset/pipe.rb', line 40

def [](*args)
  self.class[*args]
end

#bind(context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



44
45
46
47
48
49
50
51
52
53
# File 'changeset/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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



70
71
72
# File 'changeset/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) ⇒ Object Also known as: >>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'changeset/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

#for_diff(data) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



74
75
76
# File 'changeset/lib/rom/changeset/pipe.rb', line 74

def for_diff(data)
  use_for_diff ? diff_processor.call(data) : data
end

#new(processor, **opts) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



78
79
80
# File 'changeset/lib/rom/changeset/pipe.rb', line 78

def new(processor, **opts)
  self.class.new(processor, **options, **opts)
end