undo-serializer-primitive 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +19 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +87 -0
- data/Rakefile +10 -0
- data/VERSION +1 -0
- data/lib/undo/serializer/primitive.rb +51 -0
- data/spec/integration/undo_spec.rb +11 -0
- data/spec/spec_helper_lite.rb +5 -0
- data/spec/support/ci_helper.rb +16 -0
- data/spec/undo/serializer/primitive_spec.rb +25 -0
- data/undo-serializer-primitive.gemspec +24 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 031ec569b6a114811f4c67bf1baeaeb2f4fa979f
|
4
|
+
data.tar.gz: ea70c501531551cba3236852cb51121c9b7d6433
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6dfc7415827ddcf257e72b4d3963ae5d2a0b5b7272e36ff43fe9d16d2ed6624b06360b56502ceffa96bf0b8e9ecd75d135bf3f55b7172fb18d9fba5cb8adae09
|
7
|
+
data.tar.gz: cfac39e16fa802d86a911bc1a826a58a2ad9ed3ac1e81c8d55f556035d582d273855a8bdb2cd30b941f9b5729e5b58b4d6750b9288da4ff251c4046055438bf7
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
undo-serializer-primitive
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.1
|
data/.travis.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.1
|
4
|
+
- 2.0
|
5
|
+
- 1.9.3
|
6
|
+
- ruby-head
|
7
|
+
- rbx
|
8
|
+
- jruby-19mode
|
9
|
+
- jruby-head
|
10
|
+
|
11
|
+
matrix:
|
12
|
+
allow_failures:
|
13
|
+
- rvm: ruby-head
|
14
|
+
- rvm: rbx
|
15
|
+
- rvm: jruby-19mode
|
16
|
+
- rvm: jruby-head
|
17
|
+
|
18
|
+
script:
|
19
|
+
- "bundle exec rake ci:all"
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Alexander Paramonov
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
Undo
|
2
|
+
==========
|
3
|
+
[![Build Status](https://travis-ci.org/AlexParamonov/undo-serializer-primitive.png?branch=master)](https://travis-ci.org/AlexParamonov/undo-serializer-primitive)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/AlexParamonov/undo-serializer-primitive/badge.png?branch=master)](https://coveralls.io/r/AlexParamonov/undo-serializer-primitive?branch=master)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/AlexParamonov/undo-serializer-primitive.png)](https://codeclimate.com/github/AlexParamonov/undo-serializer-primitive)
|
6
|
+
[![Gemnasium Build Status](https://gemnasium.com/AlexParamonov/undo-serializer-primitive.png)](http://gemnasium.com/AlexParamonov/undo-serializer-primitive)
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/undo-serializer-primitive.png)](http://badge.fury.io/rb/undo-serializer-primitive)
|
8
|
+
|
9
|
+
Serializer for primitives for [Undo gem](https://github.com/AlexParamonov/undo).
|
10
|
+
|
11
|
+
Serializes booleans, integers, floats, empty arrays and hashes, etc.
|
12
|
+
|
13
|
+
Contents
|
14
|
+
---------
|
15
|
+
1. Installation
|
16
|
+
1. Usage
|
17
|
+
1. Requirements
|
18
|
+
1. Contacts
|
19
|
+
1. Compatibility
|
20
|
+
1. Contributing
|
21
|
+
1. Copyright
|
22
|
+
|
23
|
+
Installation
|
24
|
+
------------
|
25
|
+
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
|
28
|
+
gem 'undo-serializer-primitive'
|
29
|
+
|
30
|
+
And then execute:
|
31
|
+
|
32
|
+
$ bundle
|
33
|
+
|
34
|
+
Or install it yourself as:
|
35
|
+
|
36
|
+
$ gem install undo-serializer-primitive
|
37
|
+
|
38
|
+
|
39
|
+
Usage
|
40
|
+
-----
|
41
|
+
|
42
|
+
Primivite serializer best applicable as extension to another serializers. It
|
43
|
+
takes the responsibility of serializing primitive values, which mostly are the
|
44
|
+
edge cases for another serializers:
|
45
|
+
|
46
|
+
primitive_serializer = Undo::Serializer::Primitive.new
|
47
|
+
primitive_serializer.serialize(object) if primitive_serializer.serialize? object
|
48
|
+
primitive_serializer.deserialize(input) if primitive_serializer.deserialize? input
|
49
|
+
|
50
|
+
Requirements
|
51
|
+
------------
|
52
|
+
1. Ruby 1.9 or above
|
53
|
+
1. Undo gem
|
54
|
+
|
55
|
+
Contacts
|
56
|
+
--------
|
57
|
+
Have questions or recommendations? Contact me via `alexander.n.paramonov@gmail.com`
|
58
|
+
Found a bug or have enhancement request? You are welcome at [Github bugtracker](https://github.com/AlexParamonov/undo-serializer-primitive/issues)
|
59
|
+
|
60
|
+
|
61
|
+
Compatibility
|
62
|
+
-------------
|
63
|
+
tested with Ruby
|
64
|
+
|
65
|
+
* 2.1
|
66
|
+
* 2.0
|
67
|
+
* 1.9.3
|
68
|
+
* ruby-head
|
69
|
+
* rbx
|
70
|
+
* jruby-19mode
|
71
|
+
* jruby-head
|
72
|
+
|
73
|
+
See [build history](http://travis-ci.org/#!/AlexParamonov/undo-serializer-primitive/builds)
|
74
|
+
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
1. [Fork repository](http://github.com/AlexParamonov/undo-serializer-primitive/fork)
|
79
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
80
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
81
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
82
|
+
5. Create new Pull Request
|
83
|
+
|
84
|
+
Copyright
|
85
|
+
---------
|
86
|
+
Copyright © 2014 Alexander Paramonov.
|
87
|
+
Released under the MIT License. See the LICENSE file for further details.
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Undo
|
2
|
+
module Serializer
|
3
|
+
class Primitive
|
4
|
+
def name
|
5
|
+
"primitive"
|
6
|
+
end
|
7
|
+
|
8
|
+
def serialize(primitive, options = {})
|
9
|
+
{
|
10
|
+
serializer: name,
|
11
|
+
object: primitive,
|
12
|
+
class_name: primitive.class.name
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def deserialize(primitive_data, options = {})
|
17
|
+
primitive_class = get_option :class_name, primitive_data
|
18
|
+
object = get_option :object, primitive_data
|
19
|
+
|
20
|
+
return case primitive_class
|
21
|
+
when "Fixnum" then object.to_i
|
22
|
+
when "Symbol" then object.to_sym
|
23
|
+
when "TrueClass" then true
|
24
|
+
when "FalseClass" then false
|
25
|
+
when "NilClass" then nil
|
26
|
+
else Kernel.send primitive_class, object
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def serialize?(object)
|
31
|
+
case object
|
32
|
+
when Integer, Float, Symbol, String, true, false, nil then true
|
33
|
+
when Array, Hash then object.empty?
|
34
|
+
else false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def deserialize?(hash)
|
39
|
+
name == (hash[:serializer] || hash["serializer"])
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def get_option(name, options)
|
44
|
+
options.fetch name.to_sym do
|
45
|
+
options.fetch name.to_s
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "spec_helper_lite"
|
2
|
+
require "undo"
|
3
|
+
require_relative '../../../undo/integration/shared_undo_integration_examples.rb'
|
4
|
+
|
5
|
+
Undo.configure do |config|
|
6
|
+
config.serializer = Undo::Serializer::Primitive.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Undo do
|
10
|
+
include_examples "undo integration"
|
11
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
if !!ENV["CI"]
|
2
|
+
require 'simplecov'
|
3
|
+
require 'coveralls'
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
Coveralls::SimpleCov::Formatter
|
7
|
+
]
|
8
|
+
|
9
|
+
SimpleCov.start do
|
10
|
+
add_filter '/spec/'
|
11
|
+
add_filter '/vendor/'
|
12
|
+
minimum_coverage(90)
|
13
|
+
end
|
14
|
+
else
|
15
|
+
require "pry"
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper_lite"
|
2
|
+
|
3
|
+
describe Undo::Serializer::Primitive do
|
4
|
+
primitives = [nil, {}, [], [nil, nil], true, false, 1, 1.0, "hello", :world]
|
5
|
+
|
6
|
+
primitives .each do |input|
|
7
|
+
input_name = input.inspect
|
8
|
+
specify "restore #{input_name}" do
|
9
|
+
expect(subject.deserialize subject.serialize(input)).to eq input
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "json storage" do
|
14
|
+
require "json"
|
15
|
+
primitives.each do |input|
|
16
|
+
input_name = input.inspect
|
17
|
+
|
18
|
+
specify "restore #{input_name}" do
|
19
|
+
storage = -> object { JSON.load(object.to_json) }
|
20
|
+
data = storage.call subject.serialize(input)
|
21
|
+
expect(subject.deserialize data).to eq input
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "undo-serializer-primitive"
|
7
|
+
spec.version = IO.read("VERSION")
|
8
|
+
spec.authors = ["Alexander Paramonov"]
|
9
|
+
spec.email = ["alexander.n.paramonov@gmail.com"]
|
10
|
+
spec.summary = %q{Serializer for primitives for Undo gem.}
|
11
|
+
spec.description = %q{Serializer for primitives for Undo gem.}
|
12
|
+
spec.homepage = "http://github.com/AlexParamonov/undo-serializer-primitive"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "undo", ">= 1.0.0.beta1"
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.0"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", ">= 3.0.0.beta1"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: undo-serializer-primitive
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Paramonov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: undo
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0.beta1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0.beta1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0.beta1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.0.beta1
|
69
|
+
description: Serializer for primitives for Undo gem.
|
70
|
+
email:
|
71
|
+
- alexander.n.paramonov@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".coveralls.yml"
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".ruby-gemset"
|
80
|
+
- ".ruby-version"
|
81
|
+
- ".travis.yml"
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- VERSION
|
87
|
+
- lib/undo/serializer/primitive.rb
|
88
|
+
- spec/integration/undo_spec.rb
|
89
|
+
- spec/spec_helper_lite.rb
|
90
|
+
- spec/support/ci_helper.rb
|
91
|
+
- spec/undo/serializer/primitive_spec.rb
|
92
|
+
- undo-serializer-primitive.gemspec
|
93
|
+
homepage: http://github.com/AlexParamonov/undo-serializer-primitive
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.1.11
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Serializer for primitives for Undo gem.
|
117
|
+
test_files:
|
118
|
+
- spec/integration/undo_spec.rb
|
119
|
+
- spec/spec_helper_lite.rb
|
120
|
+
- spec/support/ci_helper.rb
|
121
|
+
- spec/undo/serializer/primitive_spec.rb
|
122
|
+
has_rdoc:
|