{"id":19137961,"url":"https://github.com/nulldef/ciesta","last_synced_at":"2025-05-06T20:40:52.495Z","repository":{"id":59154208,"uuid":"123166940","full_name":"nulldef/ciesta","owner":"nulldef","description":"Create form objects ","archived":false,"fork":false,"pushed_at":"2019-01-22T21:26:59.000Z","size":66,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-19T14:57:56.586Z","etag":null,"topics":["form-objects","forms","patterns","ruby"],"latest_commit_sha":null,"homepage":"","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/nulldef.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-27T17:53:48.000Z","updated_at":"2024-01-03T19:34:43.000Z","dependencies_parsed_at":"2022-09-13T17:51:30.449Z","dependency_job_id":null,"html_url":"https://github.com/nulldef/ciesta","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nulldef%2Fciesta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nulldef%2Fciesta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nulldef%2Fciesta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nulldef%2Fciesta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nulldef","download_url":"https://codeload.github.com/nulldef/ciesta/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252768200,"owners_count":21801358,"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":["form-objects","forms","patterns","ruby"],"created_at":"2024-11-09T06:41:14.603Z","updated_at":"2025-05-06T20:40:52.467Z","avatar_url":"https://github.com/nulldef.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ciesta\n\n[![Build Status](https://travis-ci.org/nulldef/ciesta.svg?branch=master)](https://travis-ci.org/nulldef/ciesta)\n[![Coverage Status](https://coveralls.io/repos/github/nulldef/ciesta/badge.svg?branch=master\u0026rand=23)](https://coveralls.io/github/nulldef/ciesta?branch=master)\n[![Gem Version](https://badge.fury.io/rb/ciesta.svg)](https://badge.fury.io/rb/ciesta)\n\nCreate simple form objects\n\nSupported Ruby 2.3+\n\nYou should keep it in mind that here uses [dry-validation](https://github.com/dry-rb/dry-validation) and [dry-types](https://github.com/dry-rb/dry-types) for validation and typification respectively.\n\n- [Ciesta](#ciesta)\n  - [Installation](#installation)\n  - [Usage](#usage)\n    - [Basic case](#basic-case)\n    - [Validation](#validation)\n    - [Advanced field declaration](#advanced-field-declaration)\n      - [Types](#types)\n      - [Default value](#default-value)\n  - [Values mass update](#values-mass-update)\n  - [Contributing](#contributing)\n  - [License](#license)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"ciesta\"\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install ciesta\n\n\n## Usage\n\n### Basic case\nFor example will be used a hash with `name` and `age` attributes:\n\n```ruby\nuser = Hash[name: nil, age: nil]\n```\n\nFor setting and syncing new values let's create a form object:\n\n```ruby\nclass Form\n  include Ciesta\n\n  field :name\n  field :age\n\n  def age\n    super.to_i\n  end\nend\n\nform = Form.new(user)\n```\n\n```ruby\nform.name = \"John\"\nform.age = \"33\"\n\n...\n\nform.name # =\u003e \"John\"\nform.age # =\u003e 33\n```\n\n### Validation\nFor validating incoming values you can use `validate` method:\n\n```ruby\nclass Form\n  include Ciesta\n\n  field :name\n  field :age\n\n  validate do\n    required(:name).filled\n    required(:age).filled(gt?: 18)\n  end\nend\n\nform = Form.new(user)\n```\n\nAn attempt to sync with invalid form will raise `Ciesta::FormNotValid` error.\n\n```ruby\nform.age = 15\nform.valid? # =\u003e false\nform.errors # =\u003e { age: [\"must be greater than 18\"] }\n...\nform.age = 42\nform.valid?  # =\u003e true\n```\n\n### Advanced field declaration\n\n#### Types\nYou can define the type of a field using `Ciesta::Types` namespace.\n\n```ruby\nfield :age, type: Ciesta::Types::Coercible::Int\n...\nform.age = \"42\"\nform.age # =\u003e 42\n```\n\nDefault type is `Ciesta::Types::Any`.\n\n#### Default value\nIf your attribute wasn’t set yet, but value is already in use, one can set a `default` option to avoid exceptions.\n\n```ruby\nfield :age, default: 42\n...\nform.age # =\u003e 42\n```\n\nDefault value can also be a `Proc`, wich will be called in the object context.\n\n```ruby\nclass User\n  def default_age\n    42\n  end\nend\n```\n\n```ruby\nfield :age, default: -\u003e { default_age }\n...\nform.age # =\u003e 42\n```\n\n## Values mass update\nThere are two methods for form fields mass update: `assign` and `assign!`.\n\n```ruby\nform.assign!(name: \"Neo\", age: 30)\n...\nuser.name # =\u003e \"Neo\"\nuser.age  # =\u003e 30\n```\n\n`assign!` method will raise `Ciesta::FieldNotDefined` error if one of the passed attributes is not declared in the form.\n\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at [https://github.com/nulldef/ciesta](https://github.com/nulldef/ciesta).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnulldef%2Fciesta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnulldef%2Fciesta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnulldef%2Fciesta/lists"}