{"id":21316037,"url":"https://github.com/local-ch/local_uri","last_synced_at":"2025-08-14T08:41:12.857Z","repository":{"id":55144529,"uuid":"199816109","full_name":"local-ch/local_uri","owner":"local-ch","description":"Useful and slight extension to Ruby's URI (Uniform Resource Identifiers) core module.","archived":false,"fork":false,"pushed_at":"2021-01-07T10:16:16.000Z","size":36,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-11-16T02:18:25.974Z","etag":null,"topics":["extension","ruby","rubygems","uri"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/local-ch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-31T08:43:09.000Z","updated_at":"2021-05-17T12:12:53.000Z","dependencies_parsed_at":"2022-08-14T13:20:48.213Z","dependency_job_id":null,"html_url":"https://github.com/local-ch/local_uri","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/local-ch%2Flocal_uri","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/local-ch%2Flocal_uri/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/local-ch%2Flocal_uri/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/local-ch%2Flocal_uri/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/local-ch","download_url":"https://codeload.github.com/local-ch/local_uri/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225783838,"owners_count":17523519,"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":["extension","ruby","rubygems","uri"],"created_at":"2024-11-21T18:29:23.333Z","updated_at":"2024-11-21T18:29:23.901Z","avatar_url":"https://github.com/local-ch.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Quick start guide\n\n```ruby\n  gem install local_uri\n```\n\nor add it to your Gemfile:\n\n```ruby\n  gem 'local_uri'\n```\n\nReplace ruby core URI with `LocalUri::URI`.\n\nIn plain ruby:\n```ruby\ndefine_method(:URI, -\u003e(string) { LocalUri::URI.new(string) })\n```\n\nIn rails:\n```ruby\n# config/initalizers/uri.rb\n\ndefine_method(:URI, -\u003e(string) { LocalUri::URI.new(string) })\n```\n\nIf you already have code in place that uses ruby core `URI` you can skip the replacement and just use `LocalUri::URI` directly:\n\n```ruby\nLocalUri::URI.new('https://local.ch')\n```\n\n## Working with URIs\n\n`LocalUri::URI` has the following capabilities:\n\n### Queries\n\n#### Merge hashes into url queries\n\n`merge(hash)` - returns a copy of the base LocalUri::URI with given hash being merged into the query params:\n\n```ruby\n\nuri = URI('https://yellow.local.ch/d/abc')\nuri.to_s # https://yellow.local.ch/d/abc\n\nuri.query.merge(tracking_id: 123).to_s # https://yellow.local.ch/d/abc?tracking_id=123\n```\n\nIf you place those urls directly in the view or api response, an explicit to_s is not necessary:\n\n```ruby\n\n%a{href: URI('https://yellow.local.ch/d/abc').query.merge(tracking_id: 123)} # \u003ca href=\"https://yellow.local.ch/d/abc?tracking_id=123\"/\u003e\n\n```\n\n`merge!(hash)` - the same as `merge` but changes the original URI.\n\n`merge(hash)` and `merge!(hash)` also support nested query:\n\n```ruby\n\nuri = URI('https://booking-widget.local.ch/entries/abc/bookings/new')\nuri.query.merge(booking: { people: 2 }).to_s # https://booking-widget.local.ch/entries/abc/bookings/new?booking[people]=2\n```\n\n#### Access data in queries\n\n```ruby\n\nuri = URI('https://local.ch?id=1\u0026place[name]=casa')\nuri.query[:id] # '1'\nuri.query.dig(:place, :name) # 'casa'\n```\n\n#### Remove parts of a query\n\n```ruby\nuri = URI('https://local.ch?one=1\u0026two=2\u0026three=3')\nuri.query.except(:two, :three).to_s # https://local.ch?one=1\n```\n\n`except(keys)` - Returns a uri which query includes everything except given keys.\n\n`except!(keys)` - Removes the given keys from the query of the original uri and returns the uri itself.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocal-ch%2Flocal_uri","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flocal-ch%2Flocal_uri","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocal-ch%2Flocal_uri/lists"}