module LB::Persistence::Functions

LB transproc functions

Public Class Methods

debug_p(value) click to toggle source
# File lib/lb/persistence/functions.rb, line 18
def debug_p(value)
  p value
end
debug_pp(value) click to toggle source
# File lib/lb/persistence/functions.rb, line 22
def debug_pp(value)
  pp value
end
debug_puts(value) click to toggle source
# File lib/lb/persistence/functions.rb, line 26
def debug_puts(value)
  puts value
end
empty_hash?(hash) click to toggle source
# File lib/lb/persistence/functions.rb, line 95
def empty_hash?(hash)
  hash.is_a?(Hash) && hash.values.all?(&:nil?)
end
inject_array(array, model) click to toggle source
# File lib/lb/persistence/functions.rb, line 81
def inject_array(array, model)
  t(:map_array, t(:constructor_inject, model)).call(array)
end
Also aliased as: model
inject_if_given(value, model) click to toggle source
# File lib/lb/persistence/functions.rb, line 76
def inject_if_given(value, model)
  t(:guard, ->(_v) { !model.nil? },
    t(:constructor_inject, model)).call(value)
end
model(array, model)
Alias for: inject_array
reject_array(array, function) click to toggle source
# File lib/lb/persistence/functions.rb, line 91
def reject_array(array, function)
  Array(array).reject { |value| function[value] }
end
remove_key_prefix(keys, prefix) click to toggle source
# File lib/lb/persistence/functions.rb, line 72
def remove_key_prefix(keys, prefix)
  t(:map_keys, t(:remove_prefix, prefix)).call(keys)
end
remove_key_prefix_inject(keys, prefix, model = nil) click to toggle source
# File lib/lb/persistence/functions.rb, line 65
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) click to toggle source
# File lib/lb/persistence/functions.rb, line 53
def remove_key_prefix_inject_for(hash, key, prefix, model = nil)
  t(:map_value, key,
    t(:remove_key_prefix_inject_value, prefix, model)).call(hash)
end
remove_key_prefix_inject_hash_for(hash, key, prefix, model = nil) click to toggle source
# File lib/lb/persistence/functions.rb, line 86
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_key_prefix_inject_value(value, prefix, model = nil) click to toggle source
# File lib/lb/persistence/functions.rb, line 58
def remove_key_prefix_inject_value(value, prefix, model = nil)
  compose do |ops|
    ops << t(:reject_array, t(:empty_hash?))
    ops << t(:map_array, t(:remove_key_prefix_inject, prefix, model))
  end.call(value)
end
remove_prefix(key, prefix) click to toggle source
# 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) click to toggle source
# File lib/lb/persistence/functions.rb, line 34
def remove_prefix_from_key(key, prefix)
  key.start_with?(prefix) ? key.gsub(/^#{prefix}/, '') : key
end