Sha256: b5b5f1dc1f5f55c9abc1a52c948b62e4f718bc6466e7a6aabcb136f8f168470e

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 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

  def metaform(value)
    value.nil? ? value : eval(value)
  rescue Exception => e
    value
  end

  def metamorph(datum)
    case datum.class.name
    when "Array"
      if datum.first.is_a?(Array)
        datum.map { |array| array.map { |value| metaform(value) } }
      elsif datum.first.is_a?(Hash)
        datum.map { |hash| hash.each { |key, value| hash.store(key, metaform(value)) } }
      else
        datum.map { |value| metaform(value) }
      end
    when "Hash"
      datum.each { |key, value| datum.store(key, metaform(value)) }
    else
      metaform(datum)
    end
  end

  def metatransform(datum)
    datum.empty? ? nil : (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 { |k, v| k.to_s }
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_orm-3.0.0 lib/active_orm/redis/base.rb