accord alternatives and similar shards
Based on the "Misc" category.
Alternatively, view accord alternatives based on common mentions on social networks and blogs.
-
sentry
Build/Runs your crystal application, watches files, and rebuilds/restarts app on file changes -
immutable
Thread-safe, persistent, immutable collections for the Crystal language -
crz
Functional programming library for https://github.com/crystal-lang/crystal -
crystal-web-framework-stars
โญ๏ธ Web frameworks for Crystal, most starred on Github -
cron_scheduler
Simple job scheduler with crontab patterns for Crystal Language. -
inflector.cr
Inflector shard for Crystal. A port of ActiveSupport::Inflector -
aasm.cr
:arrows_clockwise: Easy to use finite state machine for Crystal classes -
kreal
Kreal is a model sharing & RPC library built on and works with Kemal seamlessly. -
retriable.cr
Retriable.cr is a simple DSL to retry failed code blocks -
ulid
Universally Unique Lexicographically Sortable Identifier (ULID) in Crystal -
CrSerializer
Extensible annotation based serialization/deserialization library -
circuit_breaker
Implementation of the circuit breaker pattern in crystal -
burocracia.cr
๐ Zero-dependency Crystal shard to validate, generate and format Brazilian burocracias (CPF, CNPJ, CEP) -
wikicr
Wiki in crystal, using Markdown and Git, inspired by dokuwiki. Last features to build are pretty hard, if you have some time to help... :) -
m3u8
Generate and parse m3u8 playlists for HTTP Live Streaming (HLS) in Crystal. -
message_verifier.cr
Rails compatible MessageVerifier for Crystal-lang apps -
defined
This shard provides facilities for checking whether a constant exists at compile time, and for a variety of different conditional compilation options. Code can be conditionally compiled based on the existence of a constant, version number constraints, or whether an environment variable is set truthy or not.
Collect and Analyze Billions of Data Points in Real Time
Do you think we are missing an alternative of accord or a related project?
Popular Comparisons
README
Accord
A validation library for Crystal Objects which takes its inspiration from Valcro, a simple validation library for Ruby. There are some differences between the Crystal version and Ruby that you'll need to pay attention to.
Installation
Add this to your application's shard.yml
:
dependencies:
accord:
github: neovintage/accord
Usage
Validations can be defined within the object that needs to be validated or as separate classes. When using the inline method of validation,
an instance method of validate
needs to be defined. This allows crystal to access all of the instance variables that exist as part of the
instantiated object.
require "accord"
class Dog
include Accord
property name
def validate
errors.add(:name, "must be tough") if name != "spike"
end
end
dog = Dog.new
dog.name = "chuck"
dog.validate!
dog.valid? # false
dog.error_messages # ["name must be tough"]
dog.name = "spike"
dog.validate!
dog.valid? # true
Sharing Validations
One of the big values for this library is the ability to share validations across objects. When creating a validation as an object, the validator object must:
- Accept the object to be validated as a parameter to the constructor
- Define a
call
instance method that accepts a parameter of typeAccord::ErrorList
- Be a subclass of
Accord::Validator
require "accord"
class NameValidator < Accord::Validator
def initialize(context)
@context = context
end
def call(errors : Accord::ErrorList)
if @context.name != "spike"
errors.add(:name, "must be spike")
end
end
end
class Dog
include Accord
validates_with [ NameValidator ]
end
class Cat
include Accord
validates_with [ NameValidator ]
end
In cases where you need to be more explicit when sharing validator objects, specifying a union type to the constructor may be necessary. Here's a partial example:
alias AnimalValidationTypes = (Dog | Cat)
class NameValidator < Accord::Validator
def initialize(context : AnimalValidationTypes)
end
end
Mixing Validations
Accord can mix inline and sharable validations. In terms of the order of operations, sharable validations occur first and then inline
validations. The sharable validations are executed in the order that they're defined within the Array passed to validates_with
.
class Dog
include Accord
validates_with [ NameValidator, AgeValidator ]
def validate
errors.add(:base, "Shouldn't be barking") if night == true && barking == true
end
end
In this example, NameValidator
would be executed first, then AgeValidator
and finally the validate
method.
Adding Errors
The ErrorList
instance acts allows you to add new errors directly with the add
instance method. When specifying the
the name of the object it must be a symbol and when that error is turned into a string, the message is appended to the
name of the symbol.
If you don't want the error message to prepend the symbol, a special symbol identifier exists called :base
.
errors = Accord::ErrorList.new
errors.add(:base, "I like writing my own error msgs")
errors.add(:name, "must be awesome")
errors.full_messages # ["I like writing my own error msgs", "name must be awesome"]
Contributing
- Fork it ( https://github.com/neovintage/accord/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
- neovintage Rimas Silkaitis - creator, maintainer