0.0
No commit activity in last 3 years
No release in over 3 years
An encoding/decoding library with decorator pattern.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 5.10
~> 12.0
~> 0.53.0
 Project Readme

CoderDecorator Build Status Yard Docs

It's a encoding/decoding library for Ruby designed with decorator pattern, which makes it more flexible, and can be wrapped infinitely using Ruby instantiation.

This gem can refers to this pull request.

Install

gem install 'coder_decorator'

Usage

Encode data with Marshal and Base64:

require 'coder_decorator'
include CoderDecorator
coder = Coders::Base64.new(Coders::Marshal.new)
encoded_data = coder.encode(data)
coder.decode(encoded_data)

Encode data with JSON and Zip:

require 'coder_decorator'
include CoderDecorator
coder = Coders::Zip.new(Coders::JSON.new)
encoded_data = coder.encode(data)
coder.decode(encoded_data)

Coders are listed in lib/coder_decorator/coders.

Integration with Rack

require 'rack'
require 'coder_decorator'

include CoderDecorator

app = lambda do |env|
  session = env['rack.session']
  session[:count] ||= 0
  session[:count] += 1
  [200, {}, [session[:count].to_s]]
end

coder = Coders::Rescue.new(
  Coders::HMAC.new(
    Coders::Cipher.new(
      Coders::JSON.new,
      secret: 'x' * 32
    ),
    secret: 'y' * 32
  )
)

app = Rack::Builder.app(app) do
  use Rack::Session::Cookie, coder: coder, let_coder_handle_secure_encoding: true
end

Rack::Handler::WEBrick.run app