pliny 0.28.0 → 0.29.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pliny/helpers/serialize.rb +28 -29
- data/lib/pliny/version.rb +1 -1
- data/lib/template/lib/endpoints/base.rb +1 -1
- data/spec/helpers/serialize_spec.rb +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e47d761bd19ec78a4558b81ab7018a268bea25545895a67c07f21623699c21ba
|
4
|
+
data.tar.gz: ee9b112e0a31a4e9646d3e60b02f8c8538440c770dae8c6376031bbad285b7dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e5682954ac33fa5b7231c50cc59101c4fe811611e21cdc9ffc0eb06d586281692d5bc6c9231f0d553cc4b3cc275640b953cd239d219c46576d2425725f92f72
|
7
|
+
data.tar.gz: 0be3d40932b255ca70c0101cfd20a5680d5bc01fd61d8d448d27ca9f4c52043d25ec48af172122f30ab28ef4a37315c37f28358feec36edebcf7bf068a24560d
|
@@ -1,42 +1,41 @@
|
|
1
1
|
module Pliny::Helpers
|
2
2
|
module Serialize
|
3
|
-
def self.
|
4
|
-
base.
|
3
|
+
def self.registered(base)
|
4
|
+
base.helpers Helpers
|
5
|
+
base.set :serializer_class, nil
|
5
6
|
end
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
module Helpers
|
9
|
+
def serialize(data, structure = :default)
|
10
|
+
serializer_class = settings.serializer_class
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
No serializer has been specified for this endpoint. Please specify one with
|
13
|
-
`serializer Serializers::ModelName` in the endpoint.
|
14
|
-
|
15
|
-
|
12
|
+
if serializer_class.nil?
|
13
|
+
raise <<~eos.strip
|
14
|
+
No serializer has been specified for this endpoint. Please specify one with
|
15
|
+
`serializer Serializers::ModelName` in the endpoint.
|
16
|
+
eos
|
17
|
+
end
|
16
18
|
|
17
|
-
|
19
|
+
env['pliny.serializer_arity'] = data.respond_to?(:size) ? data.size : 1
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
start = Time.now
|
22
|
+
serializer_class.new(structure).serialize(data).tap do
|
23
|
+
env['pliny.serializer_timing'] = (Time.now - start).to_f
|
24
|
+
end
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
@serializer_class = serializer_class
|
37
|
-
end
|
38
|
-
|
39
|
-
attr_reader :serializer_class
|
28
|
+
# Provide a way to specify endpoint serializer class.
|
29
|
+
#
|
30
|
+
# class Endpoints::User < Base
|
31
|
+
# serializer Serializers::User
|
32
|
+
#
|
33
|
+
# get do
|
34
|
+
# encode serialize(User.all)
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
def serializer(serializer_class)
|
38
|
+
set :serializer_class, serializer_class
|
40
39
|
end
|
41
40
|
end
|
42
41
|
end
|
data/lib/pliny/version.rb
CHANGED
@@ -4,7 +4,7 @@ describe Pliny::Helpers::Serialize do
|
|
4
4
|
context "without a serializer" do
|
5
5
|
def app
|
6
6
|
Sinatra.new do
|
7
|
-
|
7
|
+
register Pliny::Helpers::Serialize
|
8
8
|
|
9
9
|
get "/" do
|
10
10
|
MultiJson.encode(serialize([]))
|
@@ -29,7 +29,7 @@ describe Pliny::Helpers::Serialize do
|
|
29
29
|
|
30
30
|
def app
|
31
31
|
Sinatra.new do
|
32
|
-
|
32
|
+
register Pliny::Helpers::Serialize
|
33
33
|
|
34
34
|
serializer Serializer
|
35
35
|
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pliny
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.29.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur Leach
|
8
8
|
- Pedro Belo
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-09-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -503,7 +503,7 @@ homepage: https://github.com/interagent/pliny
|
|
503
503
|
licenses:
|
504
504
|
- MIT
|
505
505
|
metadata: {}
|
506
|
-
post_install_message:
|
506
|
+
post_install_message:
|
507
507
|
rdoc_options: []
|
508
508
|
require_paths:
|
509
509
|
- lib
|
@@ -519,7 +519,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
519
519
|
version: '0'
|
520
520
|
requirements: []
|
521
521
|
rubygems_version: 3.0.3
|
522
|
-
signing_key:
|
522
|
+
signing_key:
|
523
523
|
specification_version: 4
|
524
524
|
summary: Basic tooling to support API apps in Sinatra
|
525
525
|
test_files: []
|