magiclabs/alchemy_cms — pull request #494 by robinboening (2014-03-17 00:03:15+00:00)
Title: Refactors essence validations and changes its API.

The API of the format validations for essences is changed by this commit. It makes the usage more easy and intuitive.

It also brings a new feature: You can define individual format matchers in the config.yml that can be used in different places, i.e. for more than one essence definition without repeating the regex again and again.

What happened exactly:

* Splits the huge essence_validations method into smaller parts.
* Removed the necessity of format_as/format_with being defined as separate keys in elements.yml
* Merged the notation of format_with and format_as to format.
* Added predefined format_matchers in config.yml and enables one to define own matchers.

Usage examples in elements.yml:

# Validates the url content to start with https://
- name: url
type: EssenceText
validate: [format: !ruby/regexp '/\Ahttps:\/\/[\S]+/']

# Validates the email content for the correct format by looking up the regex from the format_matchers in the config.yml
- name: email
type: EssenceText
validate: [format: 'email']

# Chaining validations
- name: email
type: EssenceText
validate: [presence, uniqueness, format: 'email']