Sha256: fcd9cae9e2e4b62c7b898c98b8185b3bb5095a390bfc6d74e952a2d7b0b16ca2

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

module Base

  @@evaluate = false

  def evaluate(value = true)
    @@evaluate = value
    self
  end

  private

  def evaluate?
    value = @@evaluate
    @@evaluate = false
    value
  end

  def append?(order)
    'append' == order.to_s
  end

  # rubocop:disable Lint/Eval, Lint/RescueException
  def metaform(value)
    value.nil? ? value : eval(value)
  rescue Exception
    value
  end
  # rubocop:enable Lint/Eval, Lint/RescueException

  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  def metamorph(datum)
    case datum.class.name
    when 'Array'
      data = datum.first

      if data.is_a?(Array)
        datum.map { |arr| arr.map { |val| metaform(val) } }
      elsif data.is_a?(Hash)
        datum.map { |hsh| hsh.each { |key, val| hash.store(key, metaform(val)) } }
      else
        datum.map { |val| metaform(val) }
      end
    when 'Hash'
      datum.each { |key, val| datum.store(key, metaform(val)) }
    else
      metaform(datum)
    end
  end
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength

  def metatransform(datum)
    return(nil) if datum.empty?
    evaluate? ? metamorph(datum) : datum
  end

  def milliseconds?(format)
    'milliseconds' == format.to_s
  end

  def normalize_key(key)
    key.to_s
  end

  def prepend?(order)
    'prepend' == order.to_s
  end

  def seconds?(format)
    'seconds' == format.to_s
  end

  def stringify_keys(value)
    value.map { |key, _| key.to_s }
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_orm-4.0.1 lib/active_orm/redis/base.rb
active_orm-4.0.0 lib/active_orm/redis/base.rb