Class: SnakyHash::Snake — Documentation by YARD 0.9.37

# Class: SnakyHash::Snake

Inherits:
  Module
  - Object
  - Module
  - SnakyHash::Snake
  show all

Defined in:
  lib/snaky_hash/snake.rb

## Overview

Note:

Unlike Hashie::Mash, this implementation allows for both String and Symbol key types

Creates a module that provides key conversion functionality when included

## Defined Under Namespace

Modules: SnakyModulizer

## Instance Method Summary collapse

- #included(base) ⇒ void

  Includes appropriate conversion methods into the base class.

- #initialize(key_type: :string, serializer: false) ⇒ Snake constructor

  Initialize a new Snake module.

## Constructor Details

### #initialize(key_type: :string, serializer: false) ⇒ `Snake`

Initialize a new Snake module

Parameters:

- key_type (`Symbol`) (defaults to: `:string`) —

  the type to convert keys to (:string or :symbol)

- serializer (`Boolean`) (defaults to: `false`) —

  whether to include serialization capabilities

Raises:

- (`ArgumentError`) —

  if key_type is not :string or :symbol

    30
    31
    32
    33
    34
    # File 'lib/snaky_hash/snake.rb', line 30

    def initialize(key_type: :string, serializer: false)
      super()
      @key_type = key_type
      @serializer = serializer
    end

## Instance Method Details

### #included(base) ⇒ `void`

This method returns an undefined value.

Includes appropriate conversion methods into the base class

Parameters:

- base (`Class`) —

  the class including this module

    40
    41
    42
    43
    44
    45
    46
    # File 'lib/snaky_hash/snake.rb', line 40

    def included(base)
      conversions_module = SnakyModulizer.to_mod(@key_type)
      base.include(conversions_module)
      if @serializer
        base.extend(SnakyHash::Serializer)
      end
    end