coder_decorator 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +97 -0
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0565842f5d3c837685232a7b349511616ad779b
|
4
|
+
data.tar.gz: 9e87db8f9dc04ad0795ab0daaf1741e01ba34603
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 193e8eaff80c90c4db9633149461399f8782f0c7538fe3f5154e9ea23f9a543835b76c5e637950b45606dce99961e35bc758804b33e57eadbfb7a4d046060ea2
|
7
|
+
data.tar.gz: 18e1e8afd7ba035dced6c5fc76f1f4c261110520a757333e493d616504b78666e84cebe1256658b106094d3fa3d74f726565dc93e464c4e088fad55b92514edc
|
data/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# 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/)
|
2
|
+
|
3
|
+
It'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.
|
4
|
+
|
5
|
+
This gem can refers to [this pull request](https://github.com/rack/rack/pull/1134).
|
6
|
+
|
7
|
+
# Install
|
8
|
+
|
9
|
+
```
|
10
|
+
gem install 'coder_decorator'
|
11
|
+
```
|
12
|
+
|
13
|
+
# Usage
|
14
|
+
|
15
|
+
Encode data with Marshal and Base64:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require 'coder_decorator/coders/base64'
|
19
|
+
require 'coder_decorator/coders/marshal'
|
20
|
+
include CoderDecorator
|
21
|
+
coder = Coders::Base64.new(Coders::Marshal.new)
|
22
|
+
encoded_data = coder.encode(data)
|
23
|
+
coder.decode(encoded_data)
|
24
|
+
```
|
25
|
+
|
26
|
+
Encode data with JSON and Zip:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'coder_decorator/coders/json'
|
30
|
+
require 'coder_decorator/coders/zip'
|
31
|
+
include CoderDecorator
|
32
|
+
coder = Coders::Zip.new(Coders::JSON.new)
|
33
|
+
encoded_data = coder.encode(data)
|
34
|
+
coder.decode(encoded_data)
|
35
|
+
```
|
36
|
+
|
37
|
+
To load all coders and utilities, simply do:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require 'coder_decorator'
|
41
|
+
```
|
42
|
+
|
43
|
+
All built-in coders are listed in [lib/coder_decorator/coders](lib/coder_decorator/coders).
|
44
|
+
|
45
|
+
## Use `CoderDecorator::Builder` to construct coders
|
46
|
+
|
47
|
+
`CoderDecorator::Builder` provides a convenient interface to build a coder by passing arguments instead of tediously initializing and wrapping coders, for example:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
require 'coder_decorator/builder'
|
51
|
+
CoderDecorator::Builder.build(:marshal, :base64)
|
52
|
+
```
|
53
|
+
|
54
|
+
is equivalent to:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
require 'coder_decorator/coders/marshal'
|
58
|
+
require 'coder_decorator/coders/base64'
|
59
|
+
CoderDecorator::Coders::Marshal.new(CoderDecorator::Coders::Base64.new)
|
60
|
+
```
|
61
|
+
|
62
|
+
Use array to pass arguments to the coder:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
CoderDecorator::Builder.build(:marshal, [:base64, {strict: true}])
|
66
|
+
```
|
67
|
+
|
68
|
+
Use `CoderDecorator.coder_names` to see all available coder names.
|
69
|
+
|
70
|
+
## Integration with Rack
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
require 'rack'
|
74
|
+
require 'coder_decorator/builder'
|
75
|
+
|
76
|
+
include CoderDecorator
|
77
|
+
|
78
|
+
app = lambda do |env|
|
79
|
+
session = env['rack.session']
|
80
|
+
session[:count] ||= 0
|
81
|
+
session[:count] += 1
|
82
|
+
[200, {}, [session[:count].to_s]]
|
83
|
+
end
|
84
|
+
|
85
|
+
coder = CoderDecorator::Builder.build(
|
86
|
+
:marshal,
|
87
|
+
[:cipher, {secret: 'x' * 32}],
|
88
|
+
[:hmac, {secret: 'y' * 32}],
|
89
|
+
:rescue
|
90
|
+
)
|
91
|
+
|
92
|
+
app = Rack::Builder.app(app) do
|
93
|
+
use Rack::Session::Cookie, coder: coder, let_coder_handle_secure_encoding: true
|
94
|
+
end
|
95
|
+
|
96
|
+
Rack::Handler::WEBrick.run app
|
97
|
+
```
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coder_decorator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jian Weihang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 5.10
|
19
|
+
version: '5.10'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 5.10
|
26
|
+
version: '5.10'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 12.0
|
33
|
+
version: '12.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 12.0
|
40
|
+
version: '12.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rubocop
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,6 +58,7 @@ executables: []
|
|
58
58
|
extensions: []
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
|
+
- README.md
|
61
62
|
- lib/coder_decorator.rb
|
62
63
|
- lib/coder_decorator/builder.rb
|
63
64
|
- lib/coder_decorator/coders/base64.rb
|
@@ -71,7 +72,7 @@ files:
|
|
71
72
|
- lib/coder_decorator/coders/zip.rb
|
72
73
|
- lib/coder_decorator/errors.rb
|
73
74
|
- lib/coder_decorator/name_converter.rb
|
74
|
-
homepage:
|
75
|
+
homepage: https://github.com/tonytonyjan/coder_decorator
|
75
76
|
licenses:
|
76
77
|
- MIT
|
77
78
|
metadata: {}
|