{"id":25179415,"url":"https://github.com/tbuehlmann/dry-struct-setters","last_synced_at":"2025-05-07T03:46:40.021Z","repository":{"id":62557530,"uuid":"93935224","full_name":"tbuehlmann/dry-struct-setters","owner":"tbuehlmann","description":"Setter methods for Dry::Struct subclasses","archived":false,"fork":false,"pushed_at":"2021-09-07T16:09:23.000Z","size":20,"stargazers_count":8,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-07T03:46:34.572Z","etag":null,"topics":["dry-rb","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tbuehlmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-10T11:34:54.000Z","updated_at":"2024-07-02T06:18:59.000Z","dependencies_parsed_at":"2022-11-03T06:30:34.048Z","dependency_job_id":null,"html_url":"https://github.com/tbuehlmann/dry-struct-setters","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbuehlmann%2Fdry-struct-setters","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbuehlmann%2Fdry-struct-setters/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbuehlmann%2Fdry-struct-setters/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbuehlmann%2Fdry-struct-setters/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tbuehlmann","download_url":"https://codeload.github.com/tbuehlmann/dry-struct-setters/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252810275,"owners_count":21807759,"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":["dry-rb","ruby"],"created_at":"2025-02-09T15:19:33.835Z","updated_at":"2025-05-07T03:46:40.007Z","avatar_url":"https://github.com/tbuehlmann.png","language":"Ruby","readme":"# Dry::Struct::Setters\n\n[![Gem Version](https://badge.fury.io/rb/dry-struct-setters.svg)](http://badge.fury.io/rb/dry-struct-setters) [![Build Status](https://travis-ci.org/tbuehlmann/dry-struct-setters.svg?branch=master)](https://travis-ci.org/tbuehlmann/dry-struct-setters)\n\nDry::Struct::Setters is an extension to the [Dry::Struct](https://github.com/dry-rb/dry-struct) library. Subclasses of Dry::Struct only define getter methods for its attributes by design (or preference). This library extends subclasses so they also provide setter methods.\n\n## Usage\n\nBy including the Dry::Struct::Setters module into your Dry::Struct subclass every defined attribute will get a corresponding setter method:\n\n```ruby\nmodule Types\n  include Dry::Types.module\nend\n\nclass Project \u003c Dry::Struct\n  include Dry::Struct::Setters\n\n  attribute :name, Types::String\nend\n\nproject = Project.new(name: 'some-project')\nproject.name = 'some-project-new'\n\nproject.name # =\u003e 'some-project-new'\n```\n\n### Mass Assignment\n\nIncluding the Dry::Struct::Setters module into you Dry::Struct subclass will only define setter methods, mass assigning attributes won't work with this. If you want to be able to mass assign attributes, just include the Dry::Struct::Setters::MassAssignment module, which will provide an assign_attributes method:\n\n```ruby\nmodule Types\n  include Dry::Types.module\nend\n\nclass Project \u003c Dry::Struct\n  include Dry::Struct::Setters\n  include Dry::Struct::Setters::MassAssignment\n\n  attribute :name, Types::String\n  attribute :description, Types::String\nend\n\nproject = Project.new(name: 'some-project', description: 'some-description')\n\nproject.assign_attributes(name: 'some-project-new', description: 'some-description-new')\n\nproject.name # =\u003e 'some-project-new'\nproject.description # =\u003e 'some-description-new'\n```\n\n### Convenience Class\n\nInstead of including modules you can also just use the Dry::Struct::WithSetters class which inherits from Dry::Struct and includes both modules. Note that you'll need to explicitly require it:\n\n```ruby\nrequire 'dry/struct/with_setters'\n\nmodule Types\n  include Dry::Types.module\nend\n\nclass Project \u003c Dry::Struct::WithSetters\n  attribute :name, Types::String\nend\n```\n\nHint: You can also require directly via your Gemfile:\n\n```ruby\ngem 'dry-struct-setters', require: 'dry/struct/with_setters'\n```\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'dry-struct-setters'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install dry-struct-setters\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/tbuehlmann/dry-struct-setters.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbuehlmann%2Fdry-struct-setters","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftbuehlmann%2Fdry-struct-setters","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbuehlmann%2Fdry-struct-setters/lists"}