jiffy_bag 1.0.0 → 1.0.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 +2 -2
- data/jiffy_bag.gemspec +2 -10
- data/lib/jiffy_bag.rb +67 -0
- data/lib/jiffy_bag/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1796e1b602f7071931335317ed742cfc9cccdd04
|
4
|
+
data.tar.gz: 50816d1a785efbfbeb820c2cdc8846b286c89b39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 484e98c0c713a6a6bb6c57380cb8c3e3235d782e3f67025d0e0fa03947e7157a7d7872589fe2ce70e64eb2b9b1ea04b467577f3fe2258266753633f53f81faee
|
7
|
+
data.tar.gz: 0ec408633ee77f47680c9b23b3c47482cc5550dae68ec2580b9f2f36a9446c4b96cf83479f96f70890c9a6cb09df3077ce69c8d38dbec0d8753c79ae77b4d80d
|
data/README.md
CHANGED
@@ -19,7 +19,7 @@ Or install it yourself as:
|
|
19
19
|
$ gem install jiffy_bag
|
20
20
|
|
21
21
|
## Usage
|
22
|
-
Either include or extend JiffyBag in your class depending on whether you want Instance or Class methods. The you get
|
22
|
+
Either include or extend JiffyBag in your class depending on whether you want Instance or Class methods. The you get 7 simple methods;
|
23
23
|
|
24
24
|
JiffyBag.serialize(payload)
|
25
25
|
Takes an object and serializes it to YAML.
|
@@ -42,7 +42,7 @@ Either include or extend JiffyBag in your class depending on whether you want In
|
|
42
42
|
JiffyBag.decode_as_struct(payload)
|
43
43
|
Decodes the Base64 payload, unzips it and de-serializes the YAML and if it contains a Hash it instantiates an anonymous Struct from it. This is
|
44
44
|
|
45
|
-
for the most part the you really only need
|
45
|
+
for the most part the you really only need JiffyBag.encode
|
46
46
|
|
47
47
|
payload = JiffyBag.encode(my: 'cheeky', payload: 'in a nice little package')
|
48
48
|
|
data/jiffy_bag.gemspec
CHANGED
@@ -9,19 +9,11 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["James McCarthy"]
|
10
10
|
spec.email = ["james2mccarthy@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{Package up
|
13
|
-
spec.description = %q{Takes
|
12
|
+
spec.summary = %q{Package up Ruby objects into neat little packages for sending between services.}
|
13
|
+
spec.description = %q{Takes an object zips it up into a serialized, zipped, Base64 encoded string to send between services.}
|
14
14
|
spec.homepage = 'http://github.com/james2m/jiffy_bag'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
17
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
-
# if spec.respond_to?(:metadata)
|
20
|
-
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
-
# else
|
22
|
-
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
-
# end
|
24
|
-
|
25
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
18
|
spec.bindir = "exe"
|
27
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
data/lib/jiffy_bag.rb
CHANGED
@@ -3,31 +3,98 @@ require 'yaml'
|
|
3
3
|
require 'zlib'
|
4
4
|
require "jiffy_bag/version"
|
5
5
|
|
6
|
+
# == JiffyBag
|
7
|
+
# Lets you serialize, zip and encode small Ruby objects for sending between services. The content is not
|
8
|
+
# encrypted so this is best used for internal app communication between peer services. e.g. over Sidekiq
|
9
|
+
# or using a private API.
|
10
|
+
#
|
11
|
+
# === Example
|
12
|
+
# You will usually only need JiffyBag.encode and JiffyBag.decode. To send package up a Hash to send to
|
13
|
+
# another service.
|
14
|
+
#
|
15
|
+
# payload = JiffyBag.encode(my: 'cheeky', payload: 'in a nice little package')
|
16
|
+
#
|
17
|
+
# => "eJzT1dVVUCwqTarULy4pKk0u4cqttFJIzkhNza7kKkiszMlPTLFSyMxTSFTI\ny0xOVShOTEtVKEhMzk5MT+UCAF+4FDw=\n"
|
18
|
+
#
|
19
|
+
# Do whatever you got to do get it to the other end and decode it thus;
|
20
|
+
#
|
21
|
+
# hash = JiffyBag.decode(payload)
|
22
|
+
#
|
23
|
+
# => {my: 'cheeky', payload: 'in a nice little package'}
|
24
|
+
#
|
25
|
+
# struct = JiffyBag.decode_as_struct(payload)
|
26
|
+
#
|
27
|
+
# => #<struct my="cheeky", payload="in a nice littke package">
|
28
|
+
#
|
6
29
|
module JiffyBag
|
30
|
+
# Serialize, Zip and Base64 encode a payload.
|
31
|
+
#
|
32
|
+
# ==== Parameters
|
33
|
+
#
|
34
|
+
# * +payload+ The object you want to send. This is
|
35
|
+
# any object that can be serialized with YAML.dump.
|
7
36
|
def self.encode(payload)
|
8
37
|
Base64.encode64 deflate(payload)
|
9
38
|
end
|
10
39
|
|
40
|
+
# Serialize and Zip a payload.
|
41
|
+
#
|
42
|
+
# ==== Parameters
|
43
|
+
#
|
44
|
+
# * +payload+ The object you want to send. This is any object that can be
|
45
|
+
# serialized with YAML.dump.
|
11
46
|
def self.deflate(payload)
|
12
47
|
Zlib::Deflate.deflate serialize(payload)
|
13
48
|
end
|
14
49
|
|
50
|
+
# Serialize a payload.
|
51
|
+
#
|
52
|
+
# ==== Parameters
|
53
|
+
#
|
54
|
+
# * +payload+ The object you want to send. This is
|
55
|
+
# any object that can be serialized with YAML.dump.
|
15
56
|
def self.serialize(payload)
|
16
57
|
YAML.dump(payload)
|
17
58
|
end
|
18
59
|
|
60
|
+
# De-serialize a payload. The opposite of JiffyBag.serialize.
|
61
|
+
#
|
62
|
+
# ==== Parameters
|
63
|
+
#
|
64
|
+
# * +payload+ The received payload you want to de-serialize.
|
65
|
+
# This can any string returned from YAML.dump.
|
19
66
|
def self.deserialize(payload)
|
20
67
|
YAML.load(payload)
|
21
68
|
end
|
22
69
|
|
70
|
+
# De-serialize and unzip a payload. The opposite of JiffyBag.deflate.
|
71
|
+
#
|
72
|
+
# ==== Parameters
|
73
|
+
#
|
74
|
+
# * +payload+ The received payload you want to de-serialize and unzip.
|
23
75
|
def self.inflate(payload)
|
24
76
|
deserialize Zlib::Inflate.inflate(payload)
|
25
77
|
end
|
26
78
|
|
79
|
+
# De-serialize and unzip and decode a Base64 encoded payload. The opposite
|
80
|
+
# of JiffyBag.encode.
|
81
|
+
#
|
82
|
+
# ==== Parameters
|
83
|
+
#
|
84
|
+
# * +payload+ The received payload you want to de-serialize, unzip and decode.
|
27
85
|
def self.decode(payload)
|
28
86
|
inflate Base64.decode64(payload)
|
29
87
|
end
|
30
88
|
|
89
|
+
# De-serialize and unzip and decode a Base64 encoded payload into an anonymous
|
90
|
+
# Struct. This is a convenience method for sending a Hash and re-building it
|
91
|
+
# into a Struct. Nested Hashes are not returned as Structs.
|
92
|
+
#
|
93
|
+
# ==== Parameters
|
94
|
+
#
|
95
|
+
# * +payload+ The received payload you want to de-serialize, unzip and decode.
|
96
|
+
# The original JiffyBag.encoded object needs to be a Hash for a Struct to be
|
97
|
+
# returned, any other class of object will be treated like JiffyBag.decode.
|
31
98
|
def self.decode_as_struct(payload)
|
32
99
|
object = decode(payload)
|
33
100
|
return object unless object.is_a?(Hash)
|
data/lib/jiffy_bag/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jiffy_bag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James McCarthy
|
@@ -52,7 +52,8 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
-
description: Takes
|
55
|
+
description: Takes an object zips it up into a serialized, zipped, Base64 encoded
|
56
|
+
string to send between services.
|
56
57
|
email:
|
57
58
|
- james2mccarthy@gmail.com
|
58
59
|
executables: []
|
@@ -94,5 +95,5 @@ rubyforge_project:
|
|
94
95
|
rubygems_version: 2.6.10
|
95
96
|
signing_key:
|
96
97
|
specification_version: 4
|
97
|
-
summary: Package up
|
98
|
+
summary: Package up Ruby objects into neat little packages for sending between services.
|
98
99
|
test_files: []
|