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) ⇒ 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.



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

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

Instance Method Details

#[](name) ⇒ 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.



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

def [](name)
  self.class[name]
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.



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

def bind(context)
  if processor.is_a?(Proc)
    self.class.new(Pipe[-> *args { context.instance_exec(*args, &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.



63
64
65
66
67
68
69
# File 'lib/rom/changeset/pipe.rb', line 63

def call(data)
  if processor
    processor.call(data)
  else
    data
  end
end

#compose(other, for_diff: other.is_a?(Pipe) ? 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.



51
52
53
54
55
56
57
58
59
60
# File 'lib/rom/changeset/pipe.rb', line 51

def compose(other, for_diff: other.is_a?(Pipe) ? other.use_for_diff : false)
  new_proc = processor ? processor >> other : other

  if for_diff
    diff_proc = diff_processor ? diff_processor >> other : other
    new(new_proc, 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.



71
72
73
74
75
76
77
# File 'lib/rom/changeset/pipe.rb', line 71

def for_diff(data)
  if diff_processor
    diff_processor.call(data)
  else
    data
  end
end

#new(processor, opts = EMPTY_HASH) ⇒ 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.



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

def new(processor, opts = EMPTY_HASH)
  Pipe.new(processor, opts.empty? ? options : options.merge(opts))
end