# Class LittleGhost::DataMap

Documentation version: Edge

Canonical HTML: https://littleghostai.org/docs/LittleGhost/DataMap.html

DataMap holds JSON-compatible application data with indifferent key access. It
stores every key as a String while accepting String and Symbol keys for lookup
and mutation, including in nested maps.

    state = DataMap.new(plan: {status: "active"})
    state.dig("plan", :status) # => "active"
    state.to_h                  # => {"plan" => {"status" => "active"}}

State and metadata exposed by Sessions and RunContexts use DataMap so Ruby
code can use either key form while session stores keep one portable shape.
Values are limited to JSON primitives, Arrays, and mappings. A mapping that
supplies both a String and Symbol form of the same key is ambiguous and raises
ArgumentError.

## Inheritance

`LittleGhost::DataMap < Hash`

## Class methods

<a id="method-c-coerce"></a>
### `.coerce`

```ruby
.coerce(value)
```

Returns `value` when it is already a DataMap, or normalizes a mapping.

<a id="method-c-new"></a>
### `.new`

```ruby
.new(value = {})
```

Builds a deeply normalized map from `value`.

## Instance methods

<a id="method-i-5B-5D"></a>
### `#[]`

```ruby
#[](key)
```

Looks up `key` after canonicalizing it to a String.

<a id="method-i-5B-5D-3D"></a>
### `#[]=`

```ruby
#[]=(key, value)
```

Stores `value` under the canonical String form of `key`.

<a id="method-i-delete"></a>
### `#delete`

```ruby
#delete(key, &block)
```

Removes `key` after canonicalizing it to a String.

<a id="method-i-dig"></a>
### `#dig`

```ruby
#dig(key, *names)
```

Traverses nested DataMaps with String or Symbol keys.

<a id="method-i-fetch"></a>
### `#fetch`

```ruby
#fetch(key, *defaults, &block)
```

Fetches `key` with Hash#fetch's default and block behavior.

<a id="method-i-has_key-3F"></a>
### `#has_key?`

```ruby
#has_key?(key)
```

<a id="method-i-include-3F"></a>
### `#include?`

```ruby
#include?(key)
```

<a id="method-i-initialize_copy"></a>
### `#initialize_copy`

```ruby
#initialize_copy(other)
```

Returns a deep independent DataMap copy.

<a id="method-i-key-3F"></a>
### `#key?`

```ruby
#key?(key)
```

Checks for `key` after canonicalizing it to a String.

<a id="method-i-member-3F"></a>
### `#member?`

```ruby
#member?(key)
```

<a id="method-i-merge"></a>
### `#merge`

```ruby
#merge(other, &block)
```

Returns a normalized copy merged with `other`.

<a id="method-i-merge-21"></a>
### `#merge!`

```ruby
#merge!(other)
```

Merges `other` after deeply normalizing its keys and values.

<a id="method-i-replace"></a>
### `#replace`

```ruby
#replace(other)
```

Replaces all entries with a deeply normalized copy of `other`.

<a id="method-i-store"></a>
### `#store`

```ruby
#store(key, value)
```

<a id="method-i-store_raw_value"></a>
### `#store_raw_value`

```ruby
#store_raw_value
```

<a id="method-i-to_h"></a>
### `#to_h`

```ruby
#to_h()
```

Produces a deep ordinary Hash with canonical String keys.

<a id="method-i-update"></a>
### `#update`

```ruby
#update(other)
```
