{"id":13878790,"url":"https://github.com/johansenja/typed_struct","last_synced_at":"2025-03-19T10:30:59.647Z","repository":{"id":47335233,"uuid":"379053314","full_name":"johansenja/typed_struct","owner":"johansenja","description":"Ruby structs but with type-checked attributes ⚡️🔐","archived":false,"fork":false,"pushed_at":"2022-12-25T20:19:02.000Z","size":25,"stargazers_count":15,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-17T06:11:42.552Z","etag":null,"topics":["rbs","ruby","struct","type-checking","type-definitions"],"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/johansenja.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-21T20:21:14.000Z","updated_at":"2022-09-16T09:17:03.000Z","dependencies_parsed_at":"2023-01-30T22:46:53.591Z","dependency_job_id":null,"html_url":"https://github.com/johansenja/typed_struct","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johansenja%2Ftyped_struct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johansenja%2Ftyped_struct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johansenja%2Ftyped_struct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johansenja%2Ftyped_struct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johansenja","download_url":"https://codeload.github.com/johansenja/typed_struct/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244407783,"owners_count":20447847,"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":["rbs","ruby","struct","type-checking","type-definitions"],"created_at":"2024-08-06T08:02:00.083Z","updated_at":"2025-03-19T10:30:59.340Z","avatar_url":"https://github.com/johansenja.png","language":"Ruby","readme":"# TypedStruct\n\nA Typed Struct is a lightweight data structure inspired by [Dry Struct](https://github.com/dry-rb/dry-struct), which allows for reading and writing properties while making use of a flexible and powerful type checking system, which also incorporates Ruby's [RBS](https://github.com/ruby/rbs/) for type definitions. \n\n## Example\n\n```ruby\nrequire 'typed_struct' # unless using rails\n\nUser = TypedStruct.new name: String, # an instance of String\n                       age: Integer, # an instance of Integer\n                       username: /\\w{4,}/, # must match given Regexp\n                       rating: (0..5), # must be value from 0 to 5\n                       type: \"User\", # must by a string with value \"User\"\n                       interests: Rbs(\"Array[String]\"), # an RBS generic type (an Array of Strings)\n                       preferences: Rbs(\"{ opt_out_of_emails: bool, additional: untyped }\") # RBS record type\n\nclive = User.new name: \"Clive\",\n                 age: 22,\n                 interests: %w[surfing skiing],\n                 preferences: { opt_out_of_emails: true, additional: { preferred_theme: :dark } },\n                 type: \"User\",\n                 rating: 4,\n                 username: \"cliveabc\"\n\nclive.age # 22\nclive.age = '22' # =\u003e Error\nclive.preferences = { \"opt_out_of_emails\" =\u003e true, \"additional\" =\u003e nil } # error - type mismatch, not Symbol keys\nclive.freeze # no more changes can be made\n```\n\nNote that a `TypedStruct` inherits from `Struct` directly, so anything from `Struct` is also available in `TypedStruct` - see [Struct docs](https://ruby-doc.org/core-3.0.1/Struct.html) for more info.\n\n**See [RBS reference](https://github.com/ruby/rbs/blob/3c046c77c3006211a1a14eedc35221ac4198f788/docs/syntax.md) for more info on writing RBS types**\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'typed_struct'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install typed_struct\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` 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/johansenja/typed_struct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohansenja%2Ftyped_struct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohansenja%2Ftyped_struct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohansenja%2Ftyped_struct/lists"}