Module: LB::Persistence::Functions

Extended by:
Transproc::Composer, Transproc::Registry
Defined in:
lib/lb/persistence/functions.rb

Overview

LB transproc functions

Class Method Summary collapse

Class Method Details

.debug_p(value) ⇒ Object



18
19
20
# File 'lib/lb/persistence/functions.rb', line 18

def debug_p(value)
  p value
end

.debug_pp(value) ⇒ Object



22
23
24
# File 'lib/lb/persistence/functions.rb', line 22

def debug_pp(value)
  pp value
end

.debug_puts(value) ⇒ Object



26
27
28
# File 'lib/lb/persistence/functions.rb', line 26

def debug_puts(value)
  puts value
end

.inject_array(array, model) ⇒ Object Also known as: model



75
76
77
# File 'lib/lb/persistence/functions.rb', line 75

def inject_array(array, model)
  t(:map_array, t(:constructor_inject, model)).call(array)
end

.inject_if_given(value, model) ⇒ Object



70
71
72
73
# File 'lib/lb/persistence/functions.rb', line 70

def inject_if_given(value, model)
  t(:guard, ->(_v) { !model.nil? },
    t(:constructor_inject, model)).call(value)
end

.remove_key_prefix(keys, prefix) ⇒ Object



66
67
68
# File 'lib/lb/persistence/functions.rb', line 66

def remove_key_prefix(keys, prefix)
  t(:map_keys, t(:remove_prefix, prefix)).call(keys)
end

.remove_key_prefix_inject(keys, prefix, model = nil) ⇒ Object



59
60
61
62
63
64
# File 'lib/lb/persistence/functions.rb', line 59

def remove_key_prefix_inject(keys, prefix, model = nil)
  compose do |ops|
    ops << t(:remove_key_prefix, prefix)
    ops << t(:inject_if_given, model)
  end.call(keys)
end

.remove_key_prefix_inject_for(hash, key, prefix, model = nil) ⇒ Object



53
54
55
56
57
# File 'lib/lb/persistence/functions.rb', line 53

def remove_key_prefix_inject_for(hash, key, prefix, model = nil)
  t(:map_value, key,
    t(:map_array,
      t(:remove_key_prefix_inject, prefix, model))).call(hash)
end

.remove_key_prefix_inject_hash_for(hash, key, prefix, model = nil) ⇒ Object



80
81
82
83
# File 'lib/lb/persistence/functions.rb', line 80

def remove_key_prefix_inject_hash_for(hash, key, prefix, model = nil)
  t(:map_value, key,
    t(:remove_key_prefix_inject, prefix, model)).call(hash)
end

.remove_prefix(key, prefix) ⇒ Object



30
31
32
# File 'lib/lb/persistence/functions.rb', line 30

def remove_prefix(key, prefix)
  remove_prefix_from_key(key.to_s, prefix).to_sym
end

.remove_prefix_from_key(key, prefix) ⇒ Object



34
35
36
# File 'lib/lb/persistence/functions.rb', line 34

def remove_prefix_from_key(key, prefix)
  key.start_with?(prefix) ? key.gsub(/^#{prefix}/, '') : key
end