{"id":16228787,"url":"https://github.com/dmitrytsepelev/store_model","last_synced_at":"2026-10-19T14:36:03.600Z","repository":{"id":40680935,"uuid":"170321215","full_name":"DmitryTsepelev/store_model","owner":"DmitryTsepelev","description":"Work with JSON-backed attributes as ActiveRecord-ish models","archived":false,"fork":false,"pushed_at":"2026-09-06T10:06:34.000Z","size":392,"stargazers_count":1234,"open_issues_count":31,"forks_count":110,"subscribers_count":7,"default_branch":"master","last_synced_at":"2026-10-11T10:27:45.606Z","etag":null,"topics":["activerecord","hacktoberfest","json","rails","ruby"],"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/DmitryTsepelev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-02-12T13:17:57.000Z","updated_at":"2026-10-08T01:09:27.000Z","dependencies_parsed_at":"2026-01-11T02:03:03.606Z","dependency_job_id":null,"html_url":"https://github.com/DmitryTsepelev/store_model","commit_stats":{"total_commits":174,"total_committers":51,"mean_commits":3.411764705882353,"dds":0.3390804597701149,"last_synced_commit":"a1e197250a0047106d8f7c8e03f86c85b292c1dc"},"previous_names":[],"tags_count":55,"template":false,"template_full_name":null,"purl":"pkg:github/DmitryTsepelev/store_model","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DmitryTsepelev%2Fstore_model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DmitryTsepelev%2Fstore_model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DmitryTsepelev%2Fstore_model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DmitryTsepelev%2Fstore_model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DmitryTsepelev","download_url":"https://codeload.github.com/DmitryTsepelev/store_model/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DmitryTsepelev%2Fstore_model/sbom","scorecard":{"id":41335,"data":{"date":"2025-08-11","repo":{"name":"github.com/DmitryTsepelev/store_model","commit":"735b86fd575110539bacd590e69c2095a11861a0"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.6,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":4,"reason":"Found 12/28 approved changesets -- score normalized to 4","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":8,"reason":"7 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 8","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/rspec.yml:1","Warn: no topLevel permission defined: .github/workflows/rubocop.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/rspec.yml:74: update your workflow using https://app.stepsecurity.io/secureworkflow/DmitryTsepelev/store_model/rspec.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/rspec.yml:77: update your workflow using https://app.stepsecurity.io/secureworkflow/DmitryTsepelev/store_model/rspec.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/rubocop.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/DmitryTsepelev/store_model/rubocop.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/rubocop.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/DmitryTsepelev/store_model/rubocop.yml/master?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: MIT-LICENSE:0","Info: FSF or OSI recognized license: MIT License: MIT-LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 17 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-14T21:39:04.581Z","repository_id":40680935,"created_at":"2025-08-14T21:39:04.581Z","updated_at":"2025-08-14T21:39:04.581Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":344872684,"owners_count":38358120,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-10-03T21:59:58.778Z","status":"online","status_checked_at":"2026-10-19T02:00:06.414Z","response_time":53,"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":["activerecord","hacktoberfest","json","rails","ruby"],"created_at":"2024-10-10T12:56:31.240Z","updated_at":"2026-10-19T14:36:03.594Z","avatar_url":"https://github.com/DmitryTsepelev.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StoreModel [![Gem Version](https://badge.fury.io/rb/store_model.svg)](https://rubygems.org/gems/store_model) ![](https://ruby-gem-downloads-badge.herokuapp.com/store_model?type=total)\n\n**StoreModel** gem allows you to wrap JSON-backed DB columns with ActiveModel-like classes.\n\n- 💪 **Powered with [Attributes API](https://api.rubyonrails.org/classes/ActiveRecord/Attributes/ClassMethods.html)**. You can use a number of familiar types or write your own\n- 🔧 **Works like ActiveModel**. Validations, enums and nested attributes work very similar to APIs provided by Rails\n- 1️⃣ **Follows single responsibility principle**. Keep the logic around the data stored in a JSON column separated from the model\n- 👷‍♂️ **Born in production**.\n\n```ruby\nclass Configuration\n  include StoreModel::Model\n\n  attribute :model, :string\n  enum :status, %i[active archived], default: :active\n\n  validates :model, :status, presence: true\nend\n\nclass Product \u003c ApplicationRecord\n  attribute :configuration, Configuration.to_type\nend\n```\n\n## Professional Support\n\nWorking on a complex Rails application and need an experienced eye?\nI'm available for consulting — [get in touch](https://dmitrytsepelev.dev/consulting).\n\n## Why should I wrap my JSON columns?\n\nImagine that you have a model `Product` with a `jsonb` column called `configuration`. This is how you likely gonna work with this column:\n\n```ruby\nproduct = Product.find(params[:id])\nif product.configuration[\"model\"] == \"spaceship\"\n  product.configuration[\"color\"] = \"red\"\nend\nproduct.save\n```\n\nThis approach works fine when you don't have a lot of keys with logic around them and just read the data. However, when you start working with that data more intensively–you may find the code a bit verbose and error-prone.\n\nFor instance, try to find a way to validate `:model` value to be required. Despite of the fact, that you'll have to write this validation by hand, it violates the single-responsibility principle: why parent model (`Product`) should know about the logic related to a child (`Configuration`)?\n\n\u003e 📖 Read more about the motivation in the [Wrapping JSON-based ActiveRecord attributes with classes](https://evilmartians.com/chronicles/wrapping-json-based-active-record-attributes-with-classes) post\n\n## Getting started\n\nStart with creating a class for representing the hash as an object:\n\n```ruby\nclass Configuration\n  include StoreModel::Model\n\n  attribute :model, :string\n  attribute :color, :string\nend\n```\n\nAttributes should be defined using [Rails Attributes API](https://api.rubyonrails.org/classes/ActiveRecord/Attributes/ClassMethods.html). There is a number of types available out of the box, and you can always extend the type system.\n\nRegister the field in the ActiveRecord model class:\n\n```ruby\nclass Product \u003c ApplicationRecord\n  attribute :configuration, Configuration.to_type\nend\n```\n\nWhen you're done, the initial snippet could be rewritten in the following way:\n\n```ruby\nproduct = Product.find(params[:id])\nif product.configuration.model == \"spaceship\"\n  product.configuration.color = \"red\"\nend\nproduct.save\n```\n\n_Usage note: Rails and assigning Arrays/Hashes to records_\n\n- Assigned attributes must be a String, Hash, Array of Hashes, or StoreModel. For example, if the attributes are coming from a controller, be sure to convert any ActionController::Parameters as needed.\n- Any changes made to a StoreModel instance requires the attribute be flagged as dirty, either by reassignment (`self.my_stored_models = my_stored_models.map(\u0026:as_json)`) or by `will_change!` (`self.my_stored_models_will_change!`)\n- Mixing `StoreModel::NestedAttributes` into your model will allow you to use `accepts_nested_attributes_for` in the same way as ActiveRecord.\n\n```ruby\nclass Supplier \u003c ActiveRecord::Base\n  include StoreModel::NestedAttributes\n\n  has_many :bicycles, dependent: :destroy\n\n  attribute :products, Product.to_array_type\n\n  accepts_nested_attributes_for :bicycles, :products, allow_destroy: true\nend\n```\n\nThis will allow the form builders to work their magic:\n\n```erb\n\u003c%= form_with model: @supplier do |form| %\u003e\n  \u003c%= form.fields_for :products do |product_fields| %\u003e\n    \u003c%= product_fields.text_field :name %\u003e\n  \u003c% end %\u003e\n\u003c% end %\u003e\n```\n\nResulting in:\n```html\n\u003cinput type=\"text\" name=\"supplier[products_attributes][0][name]\" id=\"supplier_products_attributes_0_name\"\u003e\n```\n\nIn the controller:\n```ruby\ndef create\n  @supplier = Supplier.from_value(supplier_params)\n  @supplier.save\nend\n\nprivate\n\ndef supplier_params\n  params.require(:supplier).permit(products_attributes: [:name])\nend\n```\n\n### ActiveAdmin Integration\n\nIf you're using [ActiveAdmin](https://activeadmin.info/), enable compatibility mode to make the `has_many` form helper work with StoreModel attributes:\n\n```ruby\n# config/initializers/store_model.rb\nStoreModel.config.active_admin_compatibility = true\n```\n\nExample usage:\n\n```ruby\n# app/models/supplier.rb\nclass Supplier\n  include StoreModel::Model\n\n  attribute :title, :string\n  attribute :address, :string\nend\n\n# app/models/product.rb\nclass Product \u003c ApplicationRecord\n  include StoreModel::NestedAttributes\n\n  attribute :suppliers, Supplier.to_array_type\n  accepts_nested_attributes_for :suppliers, allow_destroy: true\nend\n\n# app/admin/products.rb\nActiveAdmin.register Product do\n  permit_params suppliers_attributes: [:title, :address, :_destroy]\n\n  form do |f|\n    f.has_many :suppliers, allow_destroy: true do |s|\n      s.input :title\n      s.input :address\n    end\n    f.actions\n  end\nend\n```\n\n## Documentation\n\n1. [Installation](./docs/installation.md)\n2. `StoreModel::Model` API:\n  * [Instantiation](./docs/instantiation.md)\n  * [Validations](./docs/validations.md)\n  * [Enums](./docs/enums.md)\n  * [Nested models](./docs/nested_models.md)\n  * [Unknown attributes](./docs/unknown_attributes.md)\n  * [Empty attributes](./docs/empty_attributes.md)\n3. [Array of stored models](./docs/array_of_stored_models.md)\n4. [Hash of stored models](./docs/hash_of_stored_models.md)\n5. [One of](./docs/one_of.md)\n6. [Alternatives](./docs/alternatives.md)\n7. [Defining custom types](./docs/defining_custom_types.md)\n8. [Disabling Parent Tracking](./docs/enable_parent_assignment.md)\n\n## Credits\n\nInitially sponsored by [Evil Martians](http://evilmartians.com).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmitrytsepelev%2Fstore_model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmitrytsepelev%2Fstore_model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmitrytsepelev%2Fstore_model/lists"}