{"id":21366131,"url":"https://github.com/tonytonyjan/coder_decorator","last_synced_at":"2025-03-16T07:42:31.830Z","repository":{"id":56843643,"uuid":"76131175","full_name":"tonytonyjan/coder_decorator","owner":"tonytonyjan","description":"An encoding/decoding library for Ruby using decorator pattern.","archived":false,"fork":false,"pushed_at":"2018-03-09T12:33:10.000Z","size":41,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-22T22:21:52.322Z","etag":null,"topics":["coder","cookie","decorator-pattern","encoding","rack","ruby"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tonytonyjan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-10T18:50:20.000Z","updated_at":"2017-03-11T08:45:06.000Z","dependencies_parsed_at":"2022-09-05T14:50:24.488Z","dependency_job_id":null,"html_url":"https://github.com/tonytonyjan/coder_decorator","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/tonytonyjan%2Fcoder_decorator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonytonyjan%2Fcoder_decorator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonytonyjan%2Fcoder_decorator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonytonyjan%2Fcoder_decorator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tonytonyjan","download_url":"https://codeload.github.com/tonytonyjan/coder_decorator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243841206,"owners_count":20356441,"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":["coder","cookie","decorator-pattern","encoding","rack","ruby"],"created_at":"2024-11-22T07:13:53.625Z","updated_at":"2025-03-16T07:42:31.804Z","avatar_url":"https://github.com/tonytonyjan.png","language":"Ruby","readme":"# CoderDecorator [![Build Status](https://travis-ci.org/tonytonyjan/coder_decorator.svg?branch=master)](https://travis-ci.org/tonytonyjan/coder_decorator) [![Yard Docs](https://img.shields.io/badge/yard-doc-blue.svg)](http://www.rubydoc.info/gems/coder_decorator/)\n\nIt's a encoding/decoding library for Ruby designed with [decorator pattern](https://en.wikipedia.org/wiki/Decorator_pattern), which makes it more flexible, and can be wrapped infinitely using Ruby instantiation.\n\nThis gem can refers to [this pull request](https://github.com/rack/rack/pull/1134).\n\n# Install\n\n```\ngem install 'coder_decorator'\n```\n\n# Usage\n\nEncode data with Marshal and Base64:\n\n```ruby\nrequire 'coder_decorator'\ninclude CoderDecorator\ncoder = Coders::Base64.new(Coders::Marshal.new)\nencoded_data = coder.encode(data)\ncoder.decode(encoded_data)\n```\n\nEncode data with JSON and Zip:\n\n```ruby\nrequire 'coder_decorator'\ninclude CoderDecorator\ncoder = Coders::Zip.new(Coders::JSON.new)\nencoded_data = coder.encode(data)\ncoder.decode(encoded_data)\n```\n\nCoders are listed in [lib/coder_decorator/coders](lib/coder_decorator/coders).\n\n## Integration with Rack\n\n```ruby\nrequire 'rack'\nrequire 'coder_decorator'\n\ninclude CoderDecorator\n\napp = lambda do |env|\n  session = env['rack.session']\n  session[:count] ||= 0\n  session[:count] += 1\n  [200, {}, [session[:count].to_s]]\nend\n\ncoder = Coders::Rescue.new(\n  Coders::HMAC.new(\n    Coders::Cipher.new(\n      Coders::JSON.new,\n      secret: 'x' * 32\n    ),\n    secret: 'y' * 32\n  )\n)\n\napp = Rack::Builder.app(app) do\n  use Rack::Session::Cookie, coder: coder, let_coder_handle_secure_encoding: true\nend\n\nRack::Handler::WEBrick.run app\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftonytonyjan%2Fcoder_decorator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftonytonyjan%2Fcoder_decorator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftonytonyjan%2Fcoder_decorator/lists"}