Sha256: 26d91211df61c4fba7e4660e96f384d6047f8a1766f5c654fa74e6bc44ed5cb1

Contents?: true

Size: 673 Bytes

Versions: 2

Compression:

Stored size: 673 Bytes

Contents

# frozen_string_literal: true

module Exclaim
  class Bind
    attr_reader :path, :json_declaration

    def initialize(path:, json_declaration: nil)
      raise UiConfigurationError.new("$bind path must be a String, found #{path.class}") unless path.is_a?(String)

      @json_declaration = json_declaration
      self.path = path
    end

    def path=(value)
      @path = value
      @path_keys = @path.split('.')
      @path_keys_for_arrays = @path_keys.map do |string|
        Integer(string)
      rescue ArgumentError, TypeError
        string
      end
    end

    def evaluate(env)
      env.dig(*@path_keys_for_arrays) || env.dig(*@path_keys)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby-exclaim-0.1.0 lib/exclaim/bind.rb
ruby-exclaim-0.0.0 lib/exclaim/bind.rb