module Ifrit

Defined in:

ifrit.cr
ifrit/converter.cr
ifrit/inflector.cr
ifrit/version.cr

Constant Summary

VERSION = "0.1.3"

Macro Summary

Macro Detail

macro render_macros #

Renders convertable macros.

These convert macros are designed to provide interface for converting hash to exact type (e.g. {"asd" => "asd"} of String | Int64 => Float32 | Symbol | String to String => String). Adds next macros:

  • %typed_hash - converts given hash literal to one with given key type (key) and value type (types); without cycles;
  • %sym_hash_cast - is a shortcut for %typed_hash for symbol keys;
  • %str_hash_cast - is a shortcut for %typed_hash for string keys;
  • %typed_hash_cast - converts given variable or hash literal to one with given key (key) and value (types) type;
  • %sym_hash - is a shortcut for %typed_hash_cast for symbol keys;
  • %str_hash - is a shortcut for %typed_hash_cast for string keys;
  • %typed_array_cast - converts given array variable or array literal to one with given types (klass);
  • %typed_array - converts given array literal to array with given type (klass); without cycles;
  • %stringify_hash - calls #to_s on keys and converts all values to given type (klass);
Ifrit.str_hash({:asd => "qwe"}, String)

class Test
  extend Ifrit

  def some_method
    str_hash({:asd => "qwe"}, String)
  end
end

[View source]
macro str_hash(hash, types) #

accepts hash literal


[View source]
macro str_hash_cast(hash, types) #

[View source]
macro stringify_hash(hash, types) #

accepts any hash


[View source]
macro sym_hash(hash, types) #

accepts hash literal


[View source]
macro sym_hash_cast(hash, types) #

accepts any hash or named tuple example: Ifrit.as_sym_hash(hash, String | Int32)


[View source]
macro typed_array(arr, klass) #

accepts array literal


[View source]
macro typed_array_cast(arr, klass) #

accepts any array


[View source]
macro typed_hash(hash, key, types) #

accepts only hash literals example: Ifrit.typed_hash({"a" => 1, "b" => "b"}, String, Int32 | String)


[View source]
macro typed_hash_cast(hash, key, types) #

accepts any hash


[View source]