Sha256: 86f35f850f43cb4f74594f56776ac9556bf741f299424ded2156b1df702968f4
Contents?: true
Size: 1.43 KB
Versions: 7
Compression:
Stored size: 1.43 KB
Contents
# frozen_string_literal: true class Serega module SeregaPlugins module Preloads # # Utility that helps to transform user provided preloads to hash # class FormatUserPreloads METHODS = { Array => :array_to_hash, FalseClass => :nil_to_hash, Hash => :hash_to_hash, NilClass => :nil_to_hash, String => :string_to_hash, Symbol => :symbol_to_hash }.freeze private_constant :METHODS class << self # # Transforms user provided preloads to hash # # @param value [Array,Hash,String,Symbol,nil,false] preloads # # @return [Hash] preloads transformed to hash # def call(value) send(METHODS.fetch(value.class), value) end private def array_to_hash(values) values.each_with_object({}) do |value, obj| obj.merge!(call(value)) end end def hash_to_hash(values) values.each_with_object({}) do |(key, value), obj| obj[key.to_sym] = call(value) end end def nil_to_hash(_value) {} end def string_to_hash(value) symbol_to_hash(value.to_sym) end def symbol_to_hash(value) {value => {}} end end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems