Sha256: 4c5984c11bc0d3ae216f3fd6c96126d8328b4faaea0d07f7f73a9a76065e61d6

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

module Base

  @@evaluate = false

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

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

  private

  def metaform(value)
    value.nil? ? value : (eval(value) rescue value)
  end

  def metamorph(args)
    case args.class.name
    when 'Array'.freeze
      args.first.is_a?(Array) ? args.map { |h| h.map { |v| metaform(v) } } : args.map { |v| metaform(v) }
    when 'Hash'.freeze
      args.each { |k, v| args[k] = metaform(v) }
    else
      metaform(args)
    end
  end

  def metatransform(value)
    value.empty? ? nil : (evaluate? ? metamorph(value) : value)
  end

  def normalize_key(key)
    key.to_s
  end

  def stringify_keys(value)
    value.map { |k, v| k.to_s }
  end

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

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

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

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

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_orm-2.4.0 lib/active_orm/redis/base.rb
active_orm-2.3.0 lib/active_orm/redis/base.rb