{"id":21519339,"url":"https://github.com/alexwayfer/formalism-r18n_errors","last_synced_at":"2026-03-06T18:03:03.175Z","repository":{"id":40314935,"uuid":"278696493","full_name":"AlexWayfer/formalism-r18n_errors","owner":"AlexWayfer","description":"Errors for Formalism via R18n","archived":false,"fork":false,"pushed_at":"2025-04-04T14:05:34.000Z","size":173,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T22:08:46.940Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlexWayfer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-10T17:39:03.000Z","updated_at":"2025-01-06T01:37:17.000Z","dependencies_parsed_at":"2024-04-29T09:26:19.799Z","dependency_job_id":null,"html_url":"https://github.com/AlexWayfer/formalism-r18n_errors","commit_stats":{"total_commits":73,"total_committers":2,"mean_commits":36.5,"dds":"0.31506849315068497","last_synced_commit":"971b93557bcb56bdf079fe8bb53453db620aa352"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexWayfer%2Fformalism-r18n_errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexWayfer%2Fformalism-r18n_errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexWayfer%2Fformalism-r18n_errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexWayfer%2Fformalism-r18n_errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexWayfer","download_url":"https://codeload.github.com/AlexWayfer/formalism-r18n_errors/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248119294,"owners_count":21050755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T00:57:28.755Z","updated_at":"2026-03-06T18:03:03.084Z","avatar_url":"https://github.com/AlexWayfer.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Formalism R18n Errors\n\n[![Cirrus CI - Base Branch Build Status](https://img.shields.io/cirrus/github/AlexWayfer/formalism-r18n_errors?style=flat-square)](https://cirrus-ci.com/github/AlexWayfer/formalism-r18n_errors)\n[![Codecov branch](https://img.shields.io/codecov/c/github/AlexWayfer/formalism-r18n_errors/main.svg?style=flat-square)](https://codecov.io/gh/AlexWayfer/formalism-r18n_errors)\n[![Code Climate](https://img.shields.io/codeclimate/maintainability/AlexWayfer/formalism-r18n_errors.svg?style=flat-square)](https://codeclimate.com/github/AlexWayfer/formalism-r18n_errors)\n[![Inline docs](https://inch-ci.org/github/AlexWayfer/formalism-r18n_errors.svg?branch=main)](https://inch-ci.org/github/AlexWayfer/formalism-r18n_errors)\n[![license](https://img.shields.io/github/license/AlexWayfer/formalism-r18n_errors.svg?style=flat-square)](LICENSE.txt)\n[![Gem](https://img.shields.io/gem/v/formalism-r18n_errors.svg?style=flat-square)](https://rubygems.org/gems/formalism-r18n_errors)\n\nErrors for [Formalism](https://github.com/AlexWayfer/formalism)\nvia [R18n](https://github.com/r18n/r18n).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'formalism-r18n_errors'\n```\n\nAnd then execute:\n\n```shell\nbundle install\n```\n\nOr install it yourself as:\n\n```shell\ngem install formalism-r18n_errors\n```\n\n## Usage\n\n```ruby\nrequire 'formalism/r18n_errors'\n\nmodule MyProject\n  module Forms\n    class Base \u003c Formalism::Form\n      include Formalism::R18nErrors\n\n      def initialize(*)\n        ## This is an example, but some value is required\n        @errors_key = self.class.name.split('::')[2].underscore.to_sym\n\n        super\n      end\n    end\n\n    class GeoLocation \u003c Base\n      field :address\n    end\n\n    class User \u003c Base\n      field :name, String\n\n      ## `:errors_key` can be changed for nested forms\n      nested :location, GeoLocation, errors_key: :geolocation\n\n      private\n\n      def validate\n        ## `add_error` is the alias for `errors.add errors_key, *` (`:user` in this case)\n        add_error :name, :is_empty if name.to_s.empty?\n      end\n    end\n  end\nend\n```\n\n### Validation Helpers\n\n```ruby\nrequire 'formalism/r18n_errors/validation_helpers'\n\nmodule MyProject\n  module Forms\n    class Base \u003c Formalism::Form\n      include Formalism::R18nErrors\n      include Formalism::R18nErrors::ValidationHelpers\n\n      # ...\n    end\n\n    class User \u003c Base\n      field :name, String\n      field :country\n      field :city\n      field :score, Float\n      field :email, String\n\n      nested :location, GeoLocation\n\n      private\n\n      def validate\n        ## `errors.user.name.not_entered`\n        validate_entry :name\n\n        ## `errors.user.country.not_chosen`\n        ## `errors.user.city.not_chosen`\n        validate_choice %i[country city]\n\n        ## `errors.user.location.not_provided`\n        validate_provision :location\n\n        ## `errors.user.name.greater_than(20)`\n        validate_max_length :name, 20\n\n        ## `errors.user.name.less_than(3)`\n        validate_min_length :name, 3\n\n        ## `errors.user.score.greater_than(5)`\n        ## or\n        ## `errors.user.score.less_than(1)`\n        validate_range_entry :score, 1..5\n\n        ## Requires `email_address` gem\n        ## `errors.user.email.not_valid_email`\n        validate_email :email\n\n        ## `errors.user.key.not_valid_uuid`\n        validate_uuid :key\n\n        ## Requires `formalism-model_form` gem\n        ## `errors.user.email.already_taken`\n        validate_uniqueness :email\n        ## `errors.user.itself.already_exists.country_and_city`\n        validate_uniqueness %i[country city]\n      end\n    end\n  end\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bundle install` to install dependencies.\n\nThen, run `toys rspec` to run the tests.\n\nTo install this gem onto your local machine, run `toys gem install`.\n\nTo release a new version, run `toys gem release %version%`.\nSee how it works [here](https://github.com/AlexWayfer/gem_toys#release).\n\n## Contributing\n\nBug reports and pull requests are welcome on [GitHub](https://github.com/AlexWayfer/formalism-r18n_errors).\n\n## License\n\nThe gem is available as open source under the terms of the\n[MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexwayfer%2Fformalism-r18n_errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexwayfer%2Fformalism-r18n_errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexwayfer%2Fformalism-r18n_errors/lists"}