{"id":13747409,"url":"https://github.com/mz026/hash_police","last_synced_at":"2025-05-09T08:32:40.660Z","repository":{"id":13180691,"uuid":"15864032","full_name":"mz026/hash_police","owner":"mz026","description":"a gem to check whether given two hashes are of the same format","archived":false,"fork":false,"pushed_at":"2018-06-19T04:46:55.000Z","size":22,"stargazers_count":34,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-12T05:46:24.464Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/hash_police/versions/0.0.4","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/mz026.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2014-01-13T09:48:24.000Z","updated_at":"2021-05-28T19:32:23.000Z","dependencies_parsed_at":"2022-09-11T01:10:22.419Z","dependency_job_id":null,"html_url":"https://github.com/mz026/hash_police","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/mz026%2Fhash_police","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mz026%2Fhash_police/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mz026%2Fhash_police/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mz026%2Fhash_police/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mz026","download_url":"https://codeload.github.com/mz026/hash_police/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253217203,"owners_count":21873038,"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":[],"created_at":"2024-08-03T06:01:27.892Z","updated_at":"2025-05-09T08:32:40.374Z","avatar_url":"https://github.com/mz026.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/mz026/hash_police.svg?branch=master)](https://travis-ci.org/mz026/hash_police)\n[![Code Climate](https://codeclimate.com/github/mz026/hash_police/badges/gpa.svg)](https://codeclimate.com/github/mz026/hash_police)\n\n# HashPolice\nA gem to check whether given to hashes are of the same format\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'hash_police'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install hash_police\n\n## Usage\n\n```ruby\nrule = {\n  :name =\u003e \"a string\",\n  :age =\u003e 28,\n  :favorites =\u003e [ \"a string\" ],\n  :locations =\u003e [\n    { :name =\u003e \"string\", :duration =\u003e 3 }\n  ]\n}\n\nvalid = {\n  :name =\u003e \"Jack\",\n  :age =\u003e 28,\n  :favorites =\u003e [ \"sport\", \"music\" ],\n  :locations =\u003e [\n    { :name =\u003e \"Taiwan\", :duration =\u003e 25 },\n    { :name =\u003e \"US\", :duration =\u003e 5 }\n  ]\n}\n\ninvalid = {\n  :name =\u003e [],\n  :age =\u003e \"not a number\",\n  :locations =\u003e [\n    { :name =\u003e \"Taiwan\", :duration =\u003e 25 },\n    { :name =\u003e 23 }\n  ]\n}\n\npolice = HashPolice::Police.new(rule)\n\nresult = police.check(valid)\nresult.passed? # =\u003e true\nresult.error_messages # =\u003e \"\"\n\nresult = police.check(invalid)\nresult.passed? # =\u003e false\nresult.error_messages #=\u003e \"`name`: expect String, got Array; `favorites`: missing; `locations.1.name`: expect String, got Array; `locations.1.duration`: missing\"\n```\n\n## RSpec matcher:\n\n`HashPolice` provides a RSpec matcher `have_the_same_hash_format_as` checking the formats of two hashes.\n\n```ruby\n  require 'hash_police/rspec_matcher'\n\n  it \"should be able to use the matcher `have_the_same_hash_format_as`\" do\n    expected = { 'str' =\u003e '', 'an_arr' =\u003e [ 1 ] }\n    to_be_checked = { 'str' =\u003e 'hola', :an_arr =\u003e [1,3,4] }\n\n    expect(to_be_checked).to have_the_same_hash_format_as(expected)\n  end\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmz026%2Fhash_police","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmz026%2Fhash_police","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmz026%2Fhash_police/lists"}