Paradocs: Extended Parametric gem + Documentation Generation
Declaratively define data schemas in your Ruby objects, and use them to whitelist, validate or transform inputs to your programs.
Useful for building self-documeting APIs, search or form objects. Or possibly as an alternative to Rails' strong parameters (it has no dependencies on Rails and can be used stand-alone).
$ gem install paradocs
Or with Bundler in your Gemfile.
gem 'paradocs'
Define a schema
schema = Paradocs::Schema.new do
field(:title).type(:string).present
field(:status).options(["draft", "published"]).default("draft")
field(:tags).type(:array)
end
Populate and use. Missing keys return defaults, if provided.
form = schema.resolve(title: "A new blog post", tags: ["tech"])
form.output # => {title: "A new blog post", tags: ["tech"], status: "draft"}
form.errors # => {}
Please read the documentation