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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4fdeb50812c8474db1b462be06a13943d901cc06c51044c39fffe9533c2d67d4
4
- data.tar.gz: b70639846466fc0efa37a62fc55551ec4386ccfd0ac3141e041bef88744f4610
3
+ metadata.gz: e47d761bd19ec78a4558b81ab7018a268bea25545895a67c07f21623699c21ba
4
+ data.tar.gz: ee9b112e0a31a4e9646d3e60b02f8c8538440c770dae8c6376031bbad285b7dd
5
5
  SHA512:
6
- metadata.gz: f9e248f7961808f6d862d6b77c8065afc7716cf7861ecb0c508d470819ba012a0a0cd2454352b4854bbaad4cb23f18166ace07cca14035eb514ec71fdf908a96
7
- data.tar.gz: 7b7120d718e286d1ecb7cead9ed19db8a823b4aefe66f1601d824cfc172b46c89c2cbbe2ebdccfaf0e113b8afb862bd2c85d76bf55438ca1dbd5ea89bfc3f28d
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.included(base)
4
- base.send :extend, ClassMethods
3
+ def self.registered(base)
4
+ base.helpers Helpers
5
+ base.set :serializer_class, nil
5
6
  end
6
7
 
7
- def serialize(data, structure = :default)
8
- serializer_class = self.class.serializer_class
8
+ module Helpers
9
+ def serialize(data, structure = :default)
10
+ serializer_class = settings.serializer_class
9
11
 
10
- if serializer_class.nil?
11
- raise <<-eos.strip
12
- No serializer has been specified for this endpoint. Please specify one with
13
- `serializer Serializers::ModelName` in the endpoint.
14
- eos
15
- end
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
- env['pliny.serializer_arity'] = data.respond_to?(:size) ? data.size : 1
19
+ env['pliny.serializer_arity'] = data.respond_to?(:size) ? data.size : 1
18
20
 
19
- start = Time.now
20
- serializer_class.new(structure).serialize(data).tap do
21
- env['pliny.serializer_timing'] = (Time.now - start).to_f
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
- module ClassMethods
26
- # Provide a way to specify endpoint serializer class.
27
- #
28
- # class Endpoints::User < Base
29
- # serializer Serializers::User
30
- #
31
- # get do
32
- # encode serialize(User.all)
33
- # end
34
- # end
35
- def serializer(serializer_class)
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
@@ -1,3 +1,3 @@
1
1
  module Pliny
2
- VERSION = "0.28.0"
2
+ VERSION = "0.29.0"
3
3
  end
@@ -5,7 +5,7 @@ module Endpoints
5
5
 
6
6
  helpers Pliny::Helpers::Encode
7
7
  helpers Pliny::Helpers::Params
8
- helpers Pliny::Helpers::Serialize
8
+ register Pliny::Helpers::Serialize
9
9
 
10
10
  set :dump_errors, false
11
11
  set :raise_errors, true
@@ -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
- helpers Pliny::Helpers::Serialize
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
- helpers Pliny::Helpers::Serialize
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.28.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-05-08 00:00:00.000000000 Z
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: []