module Ifrit
Defined in:
ifrit.crifrit/converter.cr
ifrit/inflector.cr
ifrit/version.cr
Constant Summary
-
VERSION =
"0.1.3"
Macro Summary
-
render_macros
Renders convertable macros.
-
str_hash(hash, types)
accepts hash literal
- str_hash_cast(hash, types)
-
stringify_hash(hash, types)
accepts any hash
-
sym_hash(hash, types)
accepts hash literal
-
sym_hash_cast(hash, types)
accepts any hash or named tuple example: Ifrit.as_sym_hash(hash, String | Int32)
-
typed_array(arr, klass)
accepts array literal
-
typed_array_cast(arr, klass)
accepts any array
-
typed_hash(hash, key, types)
accepts only hash literals example: Ifrit.typed_hash({"a" => 1, "b" => "b"}, String, Int32 | String)
-
typed_hash_cast(hash, key, types)
accepts any hash
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
macro sym_hash_cast(hash, types)
#
accepts any hash or named tuple example: Ifrit.as_sym_hash(hash, String | Int32)
macro typed_hash(hash, key, types)
#
accepts only hash literals example: Ifrit.typed_hash({"a" => 1, "b" => "b"}, String, Int32 | String)