Sha256: fa25374362a535343bdff127fa01f6e36f2cbed2c7833dc1c2fe6934deb80ff5

Contents?: true

Size: 623 Bytes

Versions: 12

Compression:

Stored size: 623 Bytes

Contents

# frozen_string_literal: true

require "date"

module Seam
  class DeepHashAccessor
    def initialize(data)
      @data = data
      create_accessor_methods
    end

    def [](key)
      instance_variable_get(:"@#{key}")
    end

    private

    def create_accessor_methods
      @data.each do |key, value|
        define_singleton_method(key) do
          process_value(value)
        end
      end
    end

    def process_value(value)
      case value
      when Hash
        DeepHashAccessor.new(value)
      when Array
        value.map { |v| process_value(v) }
      else
        value
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
seam-2.3.0 lib/seam/deep_hash_accessor.rb
seam-2.2.0 lib/seam/deep_hash_accessor.rb
seam-2.1.0 lib/seam/deep_hash_accessor.rb
seam-2.0.1 lib/seam/deep_hash_accessor.rb
seam-2.0.0 lib/seam/deep_hash_accessor.rb
seam-2.0.0rc0 lib/seam/deep_hash_accessor.rb
seam-2.0.0b5 lib/seam/deep_hash_accessor.rb
seam-2.0.0b4 lib/seam/deep_hash_accessor.rb
seam-2.0.0b3 lib/seam/deep_hash_accessor.rb
seam-2.0.0b2 lib/seam/deep_hash_accessor.rb
seam-2.0.0b1 lib/seam/deep_hash_accessor.rb
seam-2.0.0b0 lib/seam/deep_hash_accessor.rb