{"id":15691642,"url":"https://github.com/kachick/striuct","last_synced_at":"2025-04-01T05:30:48.654Z","repository":{"id":2019156,"uuid":"2954943","full_name":"kachick/striuct","owner":"kachick","description":"Struct + validation + inheritable + default value + ...","archived":true,"fork":false,"pushed_at":"2024-05-03T08:27:30.000Z","size":816,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-25T02:51:31.206Z","etag":null,"topics":["ruby","struct","type","validation"],"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/kachick.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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}},"created_at":"2011-12-10T19:49:06.000Z","updated_at":"2024-05-03T08:30:24.000Z","dependencies_parsed_at":"2023-07-08T06:02:05.636Z","dependency_job_id":"5c6975fd-7c3d-4e10-86c2-b41e789f3557","html_url":"https://github.com/kachick/striuct","commit_stats":{"total_commits":673,"total_committers":4,"mean_commits":168.25,"dds":"0.15601783060921248","last_synced_commit":"e252765ea3d340b7102a777d9ec633d8869e1798"},"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kachick%2Fstriuct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kachick%2Fstriuct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kachick%2Fstriuct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kachick%2Fstriuct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kachick","download_url":"https://codeload.github.com/kachick/striuct/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246569007,"owners_count":20798341,"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":["ruby","struct","type","validation"],"created_at":"2024-10-03T18:22:36.951Z","updated_at":"2025-04-01T05:30:48.288Z","avatar_url":"https://github.com/kachick.png","language":"Ruby","readme":"# striuct\n\n![Build Status](https://github.com/kachick/striuct/actions/workflows/test_behaviors.yml/badge.svg?branch=main)\n[![Gem Version](https://badge.fury.io/rb/striuct.svg)](http://badge.fury.io/rb/striuct)\n\nStruct++\n\n- _**This repository is archived**_\n- _**No longer maintained**_\n- _**I didn't remove old versions on https://rubygems.org/gems/striuct, but I no longer plan to update them.**_\n\n## Usage\n\nTested in Ruby 3.2 or 3.3\n\nAdd this line to your `Gemfile`\n\n```ruby\ngem 'striuct', '~\u003e 0.10.1'\n```\n\nThen add below code into your Ruby code\n\n```ruby\nrequire 'striuct'\n```\n\n### Overview\n\n#### Case 1\n\n```ruby\nrequire 'striuct'\n\nclass Person \u003c Striuct\n  member :full_name, AND(String, /\\A.+\\z/)     # Flexible Validation\n  alias_member :name, :full_name               # Use other name\nend\n\n# Inheritable\nclass User \u003c Person\n  member :id, Integer,                        # Looks typed validation\n              default_proc: -\u003e{User.next_id}  # With default value\n\n  @id = 0\n  def self.next_id\n    @id += 1\n  end\nend\n\njohn = User.new 'john'\njohn[:name]              #=\u003e 'john'\njohn.name = ''           #=\u003e Exception        # Validate with setter\njohn.id                  #=\u003e 1\nken = User[name: 'ken']                       # Construct from hash\nken.id                   #=\u003e 2\n```\n\n#### Case 2\n\n```ruby\nclass Foo \u003c Striuct\n  member :foo\n  member :bar, Numeric\n  member :with_adjuster, Integer,\n                         \u0026-\u003ev{Integer v}      # Use adjuster before a setter\nend\n\nfoo = Foo.new\n\n# nil \u003c-\u003e unassigned\nfoo.foo                  #=\u003e nil\nfoo.assigned?(:foo)      #=\u003e false\nfoo.foo = nil\nfoo.assigned?(:foo)      #=\u003e true\n\n# Lock to a member\nfoo.lock(:foo)\nfoo.foo = nil            #=\u003e error\n\nfoo.bar = 1.2            #=\u003e pass             # memorize 1.2's class is Float\nfoo.bar = 1              #=\u003e error            # 1 is not Float\n\n# With adjuster\nfoo.with_adjuster = '5'\nfoo.with_adjuster        #=\u003e 5                # Casted via adjuster\n```\n\n#### Case 3\n\n```ruby\nclass UseMustOption \u003c Striuct\n  member :foo, Integer, must: true\nend\n\nUseMustOption.new #=\u003e InvalidOperationError \"`foo` require a value under `must` option \"\n```\n\n## Features\n\n### Strict\n\n- Easy and Flexible Validations\n  - Basically use `#===` for the validation\n  - The pattern builder DSL is just using [eqq](https://github.com/kachick/eqq)\n  - When passed the Proc, it will be evaluated in the instance context\n- Prevent to conflict member names\n- Lock setters for each member\n\n### Useful\n\n- Hook just before setters\n- Default value\n- Member aliasing\n- Inheritable\n- Handling between nil \u003c-\u003e unassigned\n- Similar API for Hash\n\n### Finally\n\n- Base API looks like Struct\n- Pure Ruby :)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkachick%2Fstriuct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkachick%2Fstriuct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkachick%2Fstriuct/lists"}