{"id":29899351,"url":"https://github.com/wtnabe/guide-rail","last_synced_at":"2025-10-10T15:41:20.581Z","repository":{"id":303166899,"uuid":"1014617095","full_name":"wtnabe/guide-rail","owner":"wtnabe","description":"A opinionated factory library to create safe, immutable Data objects from various sources using dry-schema and Data ( Ruby 3.2+ ).","archived":false,"fork":false,"pushed_at":"2025-07-06T04:32:19.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-07T20:22:16.262Z","etag":null,"topics":["dry-rb","ruby","rubygems","value-object"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wtnabe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2025-07-06T04:29:16.000Z","updated_at":"2025-07-06T11:07:16.000Z","dependencies_parsed_at":"2025-07-06T04:41:55.863Z","dependency_job_id":"39ebfb7a-6d65-45e1-b0cf-eead97f45d03","html_url":"https://github.com/wtnabe/guide-rail","commit_stats":null,"previous_names":["wtnabe/guide-rail"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/wtnabe/guide-rail","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wtnabe%2Fguide-rail","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wtnabe%2Fguide-rail/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wtnabe%2Fguide-rail/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wtnabe%2Fguide-rail/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wtnabe","download_url":"https://codeload.github.com/wtnabe/guide-rail/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wtnabe%2Fguide-rail/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001430,"owners_count":26083078,"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","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["dry-rb","ruby","rubygems","value-object"],"created_at":"2025-08-01T12:33:46.565Z","updated_at":"2025-10-10T15:41:20.562Z","avatar_url":"https://github.com/wtnabe.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GuideRail\n\n[![Gem Version](https://badge.fury.io/rb/guide-rail.svg)](https://badge.fury.io/rb/guide-rail)\n[![CI](https://github.com/wtnabe/guide-rail/actions/workflows/test.yml/badge.svg)](https://github.com/wtnabe/guide-rail/actions/workflows/test.yml)\n\n**GuideRail** is a opinionated powerful factory library for Ruby that transforms various data sources into safe, immutable `Data` objects. By leveraging the robust validation capabilities of `dry-schema`, it provides a clear and declarative way to define, validate, and instantiate your data structures.\n\nIt acts as a \"guide rail,\" ensuring that data flowing into your application (e.g., from controller params or API responses) is valid and conforms to a defined structure before being used in your domain logic or views.\n\n## Key Features\n\n- **Powerful Validation**: Built on top of `dry-schema` for comprehensive data validation and coercion. The generated Data object can be guaranteed to have the expected attribute. ( If you specify required )\n- **Immutable Data Objects**: Generates instances of Ruby's native `Data` class, preventing accidental state mutations.\n- **Flexible Input**: Accepts various data sources, including Hashes, Structs, and ActiveModel-like objects.\n- **Simple and Extendable Factory Class**: A concise and intuitive DSL for defining data factories.\n- **View-Friendly Rendering**: An optional `renderable` mode provides `nil`-safe default values, perfect for views.\n- **Functional-Programming-Friendly**: An optional `monadic` mode provides integration with functional programming paradigms by returning `Dry::Monads::Result` objects.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'guide-rail'\n```\n\nAnd then execute:\n\n```bash\n$ bundle install\n```\n\nor\n\n```bash\n$ bundle add guide-rail\n```\n\n## Usage\n\n### Most Simple\n\n```ruby\nrequire \"guide-rail\"\n\nSimpleNonNullableSchema = Dry::Schema.Params do\n  required(:name).filled(:string)\nend\n\nclass SimpleNonNullableCreator\n  extend GuideRail\n\n  schema SimpleNonNullableSchema\n  class_name :SimpleNonNullable\nend\n\nSimpleNonNullableCreator.from(name: nil) # =\u003e #\u003cDry::Schema::Result{name: nil} errors={name: [\"must be filled\"]} path=[]\u003e\nSimpleNonNullableCreator.from(name: \"John\") # =\u003e #\u003cdata SimpleNonNullable name=\"John\"\u003e\nSimpleNonNullableCreator.from({}) # =\u003e #\u003cDry::Schema::Result{} errors={name: [\"is missing\"]} path=[]\u003e\n```\n\n### Nullable Object with `renderable` option\n\n```ruby\nSimpleNullableSchema = Dry::Schema.Params do\n  required(:name).maybe(:string)\nend\n\nclass SimpleRenderableCreator\n  extend GuideRail\n\n  schema SimpleNullableSchema\n  class_name :SimpleRenderable\n  renderable true\nend\n\nSimpleRenderableCreator.from(name: nil) # =\u003e #\u003cdata SimpleRenderable name=\"\"\u003e\nSimpleRenderableCreator.from(name: \"John\") # =\u003e #\u003cdata SimpleRenderable name=\"John\"\u003e\nSimpleRenderableCreator.from({}) # =\u003e #\u003cDry::Schema::Result{} errors={name: [\"is missing\"]} path=[]\u003e\n```\n\n### extendable Data class\n\nYou can give a block to Creator class, the generated Data class can be extended by the block ( applying to `define` class method ).\n\nThis can be used to define decorator methods and conversion processes, so the generated Data class can also be used as a so-called ViewModel.\n\n```ruby\nOptionalSchema = Dry::Schema.Params do\n  optional(:name).filled(:string)\nend\n\nclass OptionalAndYieldAccepter\n  extend GuideRail\n\n  class_name :ExtendedData\n  schema OptionalSchema\n  renderable true\n\n  yield_block do\n    alias_method :name_orig, :name\n    define_method :name do\n      \"decorated #{name_orig}\"\n    end\n  end\nend\n\nOptionalAndYieldAccepter.from({}).name.start_with? \"decorated\" # =\u003e true\n```\n\n### Monadic mode\n\n```ruby\nSimpleNonNullableSchema = Dry::Schema.Params do\n  required(:name).filled(:string)\nend\n\nclass SimpleNonNullableMonadicCreator\n  extend GuideRail\n\n  schema SimpleNonNullableSchema\n  class_name :SimpleNonNullableMonadic\n  monadic true\nend\n\nSimpleNonNullableMonadicCreator.from({}).either(\n  -\u003e(e) { e.value! },\n  -\u003e(e) { e.errors.to_h }\n)\n# =\u003e {name: [\"is missing\"]}\n```\n\n## Not Implemented\n\n * i18n support\n * Railtie support\n * Transparent conversion of errors\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/wtnabe/guide-rail.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwtnabe%2Fguide-rail","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwtnabe%2Fguide-rail","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwtnabe%2Fguide-rail/lists"}