-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #337 from interagent/proper-extension-registration
Fix sinatra extension registration
- Loading branch information
Showing
5 changed files
with
34 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ Gemfile.lock | |
.bundle | ||
.ruby-* | ||
.tags | ||
.byebug_history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,41 @@ | ||
module Pliny::Helpers | ||
module Serialize | ||
def self.included(base) | ||
base.send :extend, ClassMethods | ||
def self.registered(base) | ||
base.helpers Helpers | ||
base.set :serializer_class, nil | ||
end | ||
|
||
def serialize(data, structure = :default) | ||
serializer_class = self.class.serializer_class | ||
module Helpers | ||
def serialize(data, structure = :default) | ||
serializer_class = settings.serializer_class | ||
|
||
if serializer_class.nil? | ||
raise <<-eos.strip | ||
No serializer has been specified for this endpoint. Please specify one with | ||
`serializer Serializers::ModelName` in the endpoint. | ||
eos | ||
end | ||
if serializer_class.nil? | ||
raise <<~eos.strip | ||
No serializer has been specified for this endpoint. Please specify one with | ||
`serializer Serializers::ModelName` in the endpoint. | ||
eos | ||
end | ||
|
||
env['pliny.serializer_arity'] = data.respond_to?(:size) ? data.size : 1 | ||
env['pliny.serializer_arity'] = data.respond_to?(:size) ? data.size : 1 | ||
|
||
start = Time.now | ||
serializer_class.new(structure).serialize(data).tap do | ||
env['pliny.serializer_timing'] = (Time.now - start).to_f | ||
start = Time.now | ||
serializer_class.new(structure).serialize(data).tap do | ||
env['pliny.serializer_timing'] = (Time.now - start).to_f | ||
end | ||
end | ||
end | ||
|
||
module ClassMethods | ||
# Provide a way to specify endpoint serializer class. | ||
# | ||
# class Endpoints::User < Base | ||
# serializer Serializers::User | ||
# | ||
# get do | ||
# encode serialize(User.all) | ||
# end | ||
# end | ||
def serializer(serializer_class) | ||
@serializer_class = serializer_class | ||
end | ||
|
||
attr_reader :serializer_class | ||
# Provide a way to specify endpoint serializer class. | ||
# | ||
# class Endpoints::User < Base | ||
# serializer Serializers::User | ||
# | ||
# get do | ||
# encode serialize(User.all) | ||
# end | ||
# end | ||
def serializer(serializer_class) | ||
set :serializer_class, serializer_class | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters