operators-serializer 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +18 -0
- data/.rspec +3 -0
- data/README.md +26 -18
- data/circle.yml +3 -0
- data/lib/operators-serializer.rb +1 -0
- data/lib/operators/serializer.rb +12 -4
- data/operators-serializer.gemspec +5 -4
- metadata +37 -8
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/lib/operators/serializer/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddc22412d3e693d0458a4a538bca22748f732f30
|
4
|
+
data.tar.gz: 81f6c8a2097d013c15ad167e3ae1a0d3f0f62e94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51f535320e9da06dc5029d42191c22f6ba61ef97442ff9be0199772fd0c832412111a6f40fcb04d2e02865d3aecc54b7d80725ce25b7f390a38514dc4232ae79
|
7
|
+
data.tar.gz: 79a18ad4add0bacdfccc67a358d0747135ccc6b5d26dfefe86cd588e0771c92886d46c80507cb84d334d21e3a54d2393a3913ec3639aca6d69c98084ca1296e8
|
data/.codeclimate.yml
ADDED
data/.rspec
ADDED
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# Operators::Serializer
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
[![Code Climate](https://codeclimate.com/github/operators-rb/operators-serializer/badges/gpa.svg)](https://codeclimate.com/github/operators-rb/operators-serializer)
|
4
|
+
[![CircleCI](https://circleci.com/gh/operators-rb/operators-serializer.svg?style=shield&circle-token=9542c2160ff69e57c6e71e2cd2d8ebfb5ec2abb4)](https://circleci.com/gh/operators-rb/operators-serializer)
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
@@ -12,27 +11,36 @@ Add this line to your application's Gemfile:
|
|
12
11
|
gem 'operators-serializer'
|
13
12
|
```
|
14
13
|
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install operators-serializer
|
22
|
-
|
23
14
|
## Usage
|
24
15
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
```ruby
|
17
|
+
class UserSerializer < Operators::Serializer
|
18
|
+
def as_json
|
19
|
+
{
|
20
|
+
id: id,
|
21
|
+
name: name,
|
22
|
+
email: email
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
```
|
30
27
|
|
31
|
-
|
28
|
+
**Usage in Rails controllers**
|
29
|
+
```ruby
|
30
|
+
class UsersController < ApplicationController
|
31
|
+
def index
|
32
|
+
@users = UserSerializer.serialize_collection(User.all)
|
33
|
+
end
|
34
|
+
|
35
|
+
def show
|
36
|
+
@user = UserSerializer.new(User.find_by(id: params[:id])).as_json
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
32
40
|
|
33
41
|
## Contributing
|
34
42
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/operators-rb/operators-serializer.
|
36
44
|
|
37
45
|
|
38
46
|
## License
|
data/circle.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "operators/serializer"
|
data/lib/operators/serializer.rb
CHANGED
@@ -1,7 +1,15 @@
|
|
1
|
-
require "operators/serializer/version"
|
2
|
-
|
3
1
|
module Operators
|
4
|
-
|
5
|
-
|
2
|
+
class Serializer < SimpleDelegator
|
3
|
+
def self.serialize_collection(collection, *args)
|
4
|
+
collection.map { |r| new(r).as_json(*args) }
|
5
|
+
end
|
6
|
+
|
7
|
+
def as_json(*)
|
8
|
+
raise 'Not implemented'
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_json(*)
|
12
|
+
as_json.to_json
|
13
|
+
end
|
6
14
|
end
|
7
15
|
end
|
@@ -1,16 +1,15 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'operators/serializer/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
6
|
spec.name = "operators-serializer"
|
8
|
-
spec.version =
|
7
|
+
spec.version = "0.2.0"
|
9
8
|
spec.authors = ["Kirill Shevchenko"]
|
10
9
|
spec.email = ["hello@kirillshevch.com"]
|
11
10
|
|
12
|
-
spec.summary = %q{
|
13
|
-
spec.description =
|
11
|
+
spec.summary = %q{You don’t need Active Model Serializers}
|
12
|
+
spec.description = spec.summary
|
14
13
|
spec.homepage = "http://operators-rb.org"
|
15
14
|
spec.license = "MIT"
|
16
15
|
|
@@ -23,4 +22,6 @@ Gem::Specification.new do |spec|
|
|
23
22
|
|
24
23
|
spec.add_development_dependency "bundler", "~> 1.13"
|
25
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.5.0"
|
26
|
+
spec.add_development_dependency "byebug", "~> 3.5.0"
|
26
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: operators-serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill Shevchenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,22 +38,51 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
-
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.5.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.5.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.5.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.5.0
|
69
|
+
description: You don’t need Active Model Serializers
|
42
70
|
email:
|
43
71
|
- hello@kirillshevch.com
|
44
72
|
executables: []
|
45
73
|
extensions: []
|
46
74
|
extra_rdoc_files: []
|
47
75
|
files:
|
76
|
+
- ".codeclimate.yml"
|
48
77
|
- ".gitignore"
|
78
|
+
- ".rspec"
|
49
79
|
- Gemfile
|
50
80
|
- LICENSE.txt
|
51
81
|
- README.md
|
52
82
|
- Rakefile
|
53
|
-
-
|
54
|
-
-
|
83
|
+
- circle.yml
|
84
|
+
- lib/operators-serializer.rb
|
55
85
|
- lib/operators/serializer.rb
|
56
|
-
- lib/operators/serializer/version.rb
|
57
86
|
- operators-serializer.gemspec
|
58
87
|
homepage: http://operators-rb.org
|
59
88
|
licenses:
|
@@ -75,8 +104,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
104
|
version: '0'
|
76
105
|
requirements: []
|
77
106
|
rubyforge_project:
|
78
|
-
rubygems_version: 2.5.
|
107
|
+
rubygems_version: 2.5.2
|
79
108
|
signing_key:
|
80
109
|
specification_version: 4
|
81
|
-
summary:
|
110
|
+
summary: You don’t need Active Model Serializers
|
82
111
|
test_files: []
|
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "operators/serializer"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
data/bin/setup
DELETED