github.com/imdrasil/ifrit
0.1.3 / published Jun 28, 2021 / repository
Crystal lib with different useful stuff
Ifrit 
Set of useful classes, patches and hacks. Some of them are not "good" enough so be ready to make a deal with Ifrit.
Installation
Add this to your application's shard.yml:
dependencies:
ifrit:
github: imdrasil/ifrit
Usage
This lib provides modular approach so you should specify what exactly you want to require:
require "ifrit/core" # for basic methods
require "ifrit/inheritable_json" # for particular pact like InheritableJSON
require "ifrit" # to load everything
Pacts
Core
require "ifrit/core"
Includes next methods:
#blank?- behaves same way as rails one;#present?- opposite to#blank?;#to_bool- parses string or integer for boolean value interpretation.
Converter
require "ifrit/converter"
Ifrit.typed_hash({"a" => 1, "b" => "asd"}, String, String | Int32) # Hash(String, String | Int32)
Symbol Table
require "ifrit/symbol_table"
include SymbolTable::Methods
a = s(:asd)
# ...
"asd".to_sym # :asd
Inheritable JSON
require "ifrit/inheritable_json"
class A
extend InheritableJSON
json_mapping({
a: String,
b: {type: Int32},
nillable_field1: {type: String?},
nillable_field2: {type: String?},
})
end
private class B < A
end
private class C < B
json_mapping({
with_default: {type: String?, default: "default"},
})
end
Hash with indifferent access
require "ifrit/hash_with_indifferent_access"
h = HashWithIndifferentAccess(Int32).new
h[:asd] = 23
h["asd"] # 23
Contributing
Before start working on any new feature please create an issue to discuss it.
- Fork it ( https://github.com/imdrasil/ifrit/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- imdrasil Roman Kalnytskyi - creator, maintainer
API
- Array(T)
An
Arrayis an ordered, integer-indexed collection of objects of type T. - BitArray
- Hash(K, V)
A
Hashrepresents a collection of key-value mappings, similar to a dictionary. - HashWithIndifferentAccess(V)
Allows to access values by both
StringandSymbolkey. - Ifrit
- InheritableJSON
Allows to define class with JSON definition and allows inheritance.
- NamedTuple(**T)
A named tuple is a fixed-size, immutable, stack-allocated mapping of a fixed set of keys to values.
- Nil
The
Niltype has only one possible value:nil. - Number
The top-level number type.
- Object
Objectis the base type of all Crystal objects. - String
A
Stringrepresents an immutable sequence of UTF-8 characters. - Struct
Defines class method delegation.
- SymbolTable
Allows to register symbols and then convert strings to them.
- Tuple(*T)
A tuple is a fixed-size, immutable, stack-allocated sequence of values of possibly different types.