Sha256: 096ed5fd8ea2d3fe497af8b5995965b3a2a0df2e33c157922edd9e6a1df8e00b

Contents?: true

Size: 958 Bytes

Versions: 2

Compression:

Stored size: 958 Bytes

Contents

# =========================================================================
#   Ceedling - Test-Centered Build System for C
#   ThrowTheSwitch.org
#   Copyright (c) 2010-25 Mike Karlesky, Mark VanderVoord, & Greg Williams
#   SPDX-License-Identifier: MIT
# =========================================================================

class ConfigWalkinator
  
  def fetch_value(*keys, hash:, default:nil)
    # Safe initial values
    value = default
    depth = 0

    # Set walk variable
    walk = hash

    # Walk into hash & extract value at requested key sequence
    keys.each { |symbol|
      # Validate that we can fetch something meaningful
      if !walk.is_a?( Hash) or !symbol.is_a?( Symbol ) or walk[symbol].nil?
        value = default
        break
      end

      # Walk into the hash one more level and update value
      depth += 1
      walk  = walk[symbol]
      value = walk
    } if !walk.nil?
    
    return value, depth
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ceedling-1.0.1 lib/ceedling/config_walkinator.rb
ceedling-1.0.0 lib/ceedling/config_walkinator.rb