Popularity
6.1
Declining
Activity
0.0
Stable
28
3
5
Programming language: Crystal
License: MIT License
Tags:
Data Formats
Latest version: v0.3.0
crinder alternatives and similar shards
Based on the "Data Formats" category.
Alternatively, view crinder alternatives based on common mentions on social networks and blogs.
-
Crystalizer
(De)serialize any Crystal object - out of the box. Supports JSON, YAML and Byte format. -
JSON::OnSteroids
[Crystal Lang] Handle and mutate JSON document easily -
json-schema
Describe crystal-lang JSON serializable types with JSON Schema
Learn any GitHub repo in 59 seconds
Onboard AI learns any GitHub repo in minutes and lets you chat with it to locate functionality, understand different parts, and generate new code. Use it for free at www.getonboard.dev.
Promo
getonboard.dev
Do you think we are missing an alternative of crinder or a related project?
Popular Comparisons
README
Crinder
Class based json renderer in Crystal
Installation
Add this to your application's shard.yml
:
dependencies:
crinder:
github: c910335/crinder
Usage
Basic
require "crinder"
record Todo, name : String, priority : Int32, expires_at : Time?, created_at : Time?, updated_at : Time?
class TodoRenderer < Crinder::Base(Todo)
field name : String, as: title
field priority : Int, value: ->{ priority * 10 }
field expires_at : String, as: deadline, unless: ->{ priority < 3 }
field created_at : String, if: ->{ created_at? }
field updated : Bool, value: updated?
option created_at? : Bool = false
def self.updated?
!object.updated_at.nil?
end
end
time = Time.utc(2018, 3, 14, 19, 55, 7)
todo = Todo.new("qaq", 8, time + 20.hours, time, nil)
TodoRenderer.render(todo, created_at?: true) # => "{\"title\":\"qaq\",\"priority\":80,\"deadline\":\"2018-03-15 15:55:07 UTC\",\"created_at\":\"2018-03-14 19:55:07 UTC\",\"updated\":false}"
Inheritance
class AnotherTodoRenderer < TodoRenderer
field expires_at : String, unless: ->{ priority < 1 }
field updated_at : String
remove updated
end
todo = Todo.new("wow", 6, time + 20.hours, time, time + 10.hours)
AnotherTodoRenderer.render(todo) # => "{\"title\":\"wow\",\"priority\":60,\"expires_at\":\"2018-03-15 15:55:07 UTC\",\"updated_at\":\"2018-03-15 05:55:07 UTC\"}"
Array
todos = [Todo.new("www", 8, time + 20.hours, time, nil), Todo.new("api", 10, time + 21.hours, time, nil)]
TodoRenderer.render(todos) # => "[{\"title\":\"www\",\"priority\":80,\"deadline\":\"2018-03-15 15:55:07 UTC\",\"updated\":false},{\"title\":\"api\",\"priority\":100,\"deadline\":\"2018-03-15 16:55:07 UTC\",\"updated\":false}]"
Nested
class TimeRenderer < Crinder::Base(Time?)
field year : Int
field month : Int
field day : Int
field hour : Int
field minute : Int
field second : Int
end
class NestedTodoRenderer < TodoRenderer
remove expires_at
remove updated
field created_at, with: TimeRenderer
end
todo = Todo.new("wtf", 3, time + 20.hours, time, nil)
NestedTodoRenderer.render(todo) # => "{\"title\":\"wtf\",\"priority\":30,\"created_at\":{\"year\":2018,\"month\":3,\"day\":14,\"hour\":19,\"minute\":55,\"second\":7}}"
Nilable
class NilableTodoRenderer < TodoRenderer
field expires_at : String?
field created_at : String?
field updated_at : String?
remove updated
end
todo = Todo.new("IDK", 10, nil, nil, nil)
NilableTodoRenderer.render(todo) # => "{\"title\":\"IDK\",\"priority\":100,\"expires_at\":null,\"created_at\":null,\"updated_at\":null}"
Contributing
- Fork it ( https://github.com/c910335/crinder/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
- c910335 Tatsiujin Chin - creator, maintainer
*Note that all licence references and agreements mentioned in the crinder README section above
are relevant to that project's source code only.