Class: ROM::Changeset::Pipe Private

Inherits:
Object
  • Object
show all
Extended by:
Initializer
Defined in:
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.


34
35
36
# File 'lib/rom/changeset/pipe.rb', line 34

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.


28
29
30
31
32
# File 'lib/rom/changeset/pipe.rb', line 28

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.


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

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.


38
39
40
# File 'lib/rom/changeset/pipe.rb', line 38

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.


42
43
44
45
46
47
48
49
50
51
# File 'lib/rom/changeset/pipe.rb', line 42

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.


68
69
70
# File 'lib/rom/changeset/pipe.rb', line 68

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.


53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rom/changeset/pipe.rb', line 53

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.


72
73
74
# File 'lib/rom/changeset/pipe.rb', line 72

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.


76
77
78
# File 'lib/rom/changeset/pipe.rb', line 76

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