{"id":13879605,"url":"https://github.com/pcriv/statics","last_synced_at":"2025-04-29T00:30:51.688Z","repository":{"id":44697719,"uuid":"146726283","full_name":"pcriv/statics","owner":"pcriv","description":"Base class and modules for YAML backed static models.","archived":false,"fork":false,"pushed_at":"2024-06-26T22:29:23.000Z","size":33,"stargazers_count":43,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-03T15:50:31.743Z","etag":null,"topics":["dry-rb","ruby","yaml"],"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/pcriv.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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}},"created_at":"2018-08-30T09:21:39.000Z","updated_at":"2024-06-26T22:29:24.000Z","dependencies_parsed_at":"2024-01-13T20:57:32.987Z","dependency_job_id":"967568db-c982-4561-9d2c-6568cfdda3d8","html_url":"https://github.com/pcriv/statics","commit_stats":null,"previous_names":["pablocrivella/statics"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcriv%2Fstatics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcriv%2Fstatics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcriv%2Fstatics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcriv%2Fstatics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pcriv","download_url":"https://codeload.github.com/pcriv/statics/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251410200,"owners_count":21584979,"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","yaml"],"created_at":"2024-08-06T08:02:26.587Z","updated_at":"2025-04-29T00:30:51.408Z","avatar_url":"https://github.com/pcriv.png","language":"Ruby","readme":"# Statics\n\n[![Gem](https://img.shields.io/gem/v/statics.svg?style=flat)](http://rubygems.org/gems/statics)\n[![Depfu](https://badges.depfu.com/badges/6f2f73672eae4d603d6ae923164435e2/overview.svg)](https://depfu.com/github/pcriv/statics?project=Bundler)\n[![Inline docs](http://inch-ci.org/github/pcriv/statics.svg?branch=master\u0026style=shields)](http://inch-ci.org/github/pcriv/statics)\n[![Maintainability](https://api.codeclimate.com/v1/badges/935822c7c481aa464186/maintainability)](https://codeclimate.com/github/pcriv/statics/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/935822c7c481aa464186/test_coverage)](https://codeclimate.com/github/pcriv/statics/test_coverage)\n\nBase class and modules for static models.\n\nLinks:\n\n- [API Docs](https://www.rubydoc.info/gems/statics)\n- [Contributing](https://github.com/pcriv/statics/blob/master/CONTRIBUTING.md)\n- [Code of Conduct](https://github.com/pcriv/statics/blob/master/CODE_OF_CONDUCT.md)\n\n## Requirements\n\n1. [Ruby 3.0.0](https://www.ruby-lang.org)\n\n## Installation\n\nTo install, run:\n\n```sh\ngem install statics\n```\n\nOr add the following to your Gemfile:\n\n```sh\ngem \"statics\"\n```\n\n## Usage\n\nSetting the data path:\n\n```ruby\nStatics.configure do |config|\n  config.data_path = \"data/\"\nend\n```\n\nDefining a static model:\n\n```ruby\nclass Post \u003c Statics::Model\n  filename \"posts\"\n\n  attribute :title, Types::Strict::String\nend\n```\n\n```yml\n# data/posts.yml\n---\npost1:\n  title: \"Post 1\"\n\npost2:\n  title: \"Post 2\"\n```\n\n```ruby\nPost.all\n#=\u003e #\u003cStatics::Collection records=[#\u003cPost key=:post1 title=\"Post 1\"\u003e, #\u003cPost key=:post2 title=\"Post 2\"\u003e]\u003e\nPost.where(title: \"Post 1\")\n#=\u003e #\u003cStatics::Collection records=[#\u003cPost key=:post1 title=\"Post 1\"\u003e]\u003e\nPost.where_not(title: \"Post 1\")\n#=\u003e #\u003cStatics::Collection records=[#\u003cPost key=:post2 title=\"Post 2\"\u003e]\u003e\nPost.find_by(key: :post1)\n#=\u003e #\u003cPost key=:post1 title=\"Post 1\"\u003e\nPost[:post1]\n#=\u003e #\u003cPost key=:post1 title=\"Post 1\"\u003e\nPost.pluck(:title)\n#=\u003e [\"Post 1\", \"Post 2\"]\npost = Post.first\n#=\u003e #\u003cPost key=:post1 title=\"Post 1\"\u003e\npost.key\n#=\u003e :post1\npost.title\n#=\u003e \"Post 1\"\npost.attributes\n#=\u003e {:title=\u003e\"Post 1\", :key=\u003e:post1}\n```\n\nDefining translatable attributes:\n\n```ruby\nclass Post \u003c Statics::Model\n  include Statics::Translatable\n\n  filename \"posts\"\n\n  attribute :title, Types::Strict::String\n  translatable_attribute :body\nend\n```\n\n```yml\n# data/posts.yml\n---\npost1:\n  title: \"Post 1\"\n  body:\n    en: \"Hello!\"\n    nl: \"Hallo!\"\n\npost2:\n  title: \"Post 2\"\n  body:\n    en: \"Bye!\"\n    nl: \"Doei!\"\n```\n\n```ruby\npost = Post.first\n# when I18n.locale is :en\npost.body #=\u003e \"Hello!\"\npost.body(locale: :nl) #=\u003e \"Hallo!\"\n```\n\nDefining omittable attributes with defaults:\n\n```ruby\nclass Post \u003c Statics::Model\n  include Statics::Translatable\n\n  filename \"posts\"\n\n  attribute :title, Types::Strict::String\n  # With default\n  attribute? :author, Types::Strict::String.default(\"Unknown\")\n  # Without default\n  # attribute? :author, Types::Strict::String\nend\n```\n\n```yml\n# data/posts.yml\n---\npost1:\n  title: \"Post 1\"\n  author: \"Rick Sanchez\"\n\npost2:\n  title: \"Post 2\"\n```\n\n```ruby\npost1 = Post.first\npost1.author #=\u003e \"Rick Sanchez\"\npost2 = Post.last\npost2.author #=\u003e \"Unknown\"\n```\n\nCheck [dry-types](https://dry-rb.org/gems/dry-types) for documentation about the [built-in types](https://dry-rb.org/gems/dry-types/built-in-types/).\n\n## Caveats\n\nIf you have dates in your yaml-files, use the following format for them to be handled properly: `YYYY-MM-DD`\n\n## Tests\n\nTo test, run:\n\n```\nbundle exec rspec spec/\n```\n\n## Versioning\n\nRead [Semantic Versioning](https://semver.org) for details. Briefly, it means:\n\n- Major (X.y.z) - Incremented for any backwards incompatible public API changes.\n- Minor (x.Y.z) - Incremented for new, backwards compatible, public API enhancements/fixes.\n- Patch (x.y.Z) - Incremented for small, backwards compatible, bug fixes.\n\n## License\n\nCopyright 2018 [Pablo Crivella](https://pcriv.com).\nRead [LICENSE](LICENSE) for details.\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpcriv%2Fstatics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpcriv%2Fstatics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpcriv%2Fstatics/lists"}